Archived

This topic is now archived and is closed to further replies.

creating DLL problem , weird link errors

This topic is 5061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

hi ive made a wrapper class around the direct input,keyboard and mouse. I am now putting this into a dll, but i am getting problems. Like some link errors and that. Heres my source, and the error quoted below. heres my code so far: header file
#ifndef AINPUT_H
#define AINPUT_H
#include <dinput.h>

class DInput {
private:
static DInput * reference;
LPDIRECTINPUT8 lp_DI;
~DInput();
DInput();

public:
DInput * getInstance();
LPDIRECTINPUT8 getDevice();
};

#endif


cpp file
#include "ainput.h"
#include <dinput.h>
DInput * DInput::reference;

DInput::DInput()
{
DirectInput8Create(GetModuleHandle(NULL),0x0800,
IID_IDirectInput8, (void**)&lp_DI,NULL);
}

DInput::~DInput()
{
if( lp_DI != NULL )
{
lp_DI->Release();
lp_DI=NULL;
}
}

DInput * DInput::getInstance()
{
if(reference==NULL)
reference = new DInput();

return reference;
}

LPDIRECTINPUT8	DInput:: getDevice()
{
return lp_DI;
}


def file
EXPORTS

the errors
quote:
--------------------Configuration: ainput - Win32 Debug-------------------- Linking... ainput.def : error LNK2001: unresolved external symbol DirectInput8Create Debug/ainput.lib : fatal error LNK1120: 1 unresolved externals LINK : fatal error LNK1141: failure during build of exports file Error executing link.exe. ainput.dll - 3 error(s), 0 warning(s)
Basically i dont think it can work out something about the directinput8create, like when i had all the code outside of the class, it works fine, thanks, [edited by - johnnyBravo on April 9, 2004 11:36:16 PM]

Share on other sites
The second error is probably just a cascade from the first error. The first error is probably because your DLL isn't including the library for DirectInput. Did you link against dinput8.lib?

edit: and be careful about editting your post. There's a forum bug where posts with multiple source boxes get borked.

[edited by - SiCrane on April 9, 2004 11:36:37 PM]

Share on other sites
Oh, I thought i had put it in,

but now that i have it has came down to 2 errors.

I believe it has something to do with the def
quote:

--------------------Configuration: ainput - Win32 Debug--------------------
Creating library Debug/ainput.lib and object Debug/ainput.exp
ainput.obj : error LNK2001: unresolved external symbol _IID_IDirectInput8A
Debug/ainput.dll : fatal error LNK1120: 1 unresolved externals

ainput.dll - 2 error(s), 0 warning(s)

thanks,

Share on other sites
That doesn''t seem like a problem with the def file. It looks more like you need to link against dxguid.lib as well. (Or #define INITGUID in your source file before your includes.)

Share on other sites
Oh yeah I included that now and the dll compiles now, but when i run it in my program i get another error

I call my class like so:
DInput * di;

then within the winmain method, i put:
di->getInstance();

where i get the error

quote:

--------------------Configuration: Scenario - Win32 Debug--------------------
Compiling...
Scenario.cpp
Scenario.obj : error LNK2001: unresolved external symbol "public: class DInput * __thiscall DInput::getInstance(void)" (?getInstance@DInput@@QAEPAV1@XZ)
Debug/Scenario.exe : fatal error LNK1120: 1 unresolved externals

Scenario.exe - 2 error(s), 0 warning(s)

Share on other sites
You have to declare your class as dllimport / dllexport depending on if you include the .h into your app or your dll.

And... maybe you should think about your singleton-alike construction again, it wont work like you did it now anyway.

Share on other sites
You wouldn''t be able to point out whats wrong with my singleton?

and where do i get information about dll import/export, thanks

Share on other sites
Try looking at these links: One and Two.

Using dllexport/dllimport is pretty much incompatible with using a DEF file. On the other hand, using a DEF file is pretty much incompatible with exporting a class body.

Share on other sites
ok so if i do this import export way, i don''t need to create defs for the lib file. Like will the lib file be created automatically?

Share on other sites
A .lib file will be created for your dll automatically with symbols in the export table corresponding to every function marked with __declspec(dllexport).

Share on other sites
ok heres my test dll

when i try and run it, i get the error popup
quote:

=====================
The procedure entry point ??0Input@@QAE@XZ could not be located in the dynamic link library ainput.dll

and after that i get this popup
quote:

i have no idea what this is, any ideas, thanks

.cpp
#include "ainput.h"#include <windows.h>BOOL APIENTRY DllMain( HANDLE hModule,                        DWORD  ul_reason_for_call,                        LPVOID lpReserved					 ){    switch (ul_reason_for_call)	{		case DLL_PROCESS_ATTACH:		case DLL_THREAD_ATTACH:		case DLL_THREAD_DETACH:		case DLL_PROCESS_DETACH:			break;    }    return TRUE;}void Input::setNumber(int number){	this->number=number;}int Input::getNumber(){	return this->number;}Input::Input(){	return;}

.h
#ifdef AINPUT_EXPORTS#define AINPUT_API __declspec(dllexport)#else#define AINPUT_API __declspec(dllimport)#endifclass AINPUT_API Input {private:	int number;public:	Input();	void setNumber(int number);	int getNumber();};

Share on other sites
Usually the cause of that error is the loader finding an old copy of the DLL that isn''t synchronized properly with the lib file you used to import the DLL''s symbols. Try deleting all copies of the DLL on your computer and doing a recompile.