#### Archived

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

# creating DLL problem , weird link errors

This topic is 5302 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).

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632932
• Total Posts
3009296
• ### Who's Online (See full list)

There are no registered users currently online

×