Jump to content
  • Advertisement

Archived

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

SpreeTree

Exporting variables from a dll issue

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am having trouble exporting a vaiable from my dll. I have looked at the vc6 sample code, and I am doing (as far as I can see) nothing wrong. Heres the code from the .h file (well a couple stuck together )

#ifdef TEST_EXPORTS
#define MEXPORT	 __declspec(dllimport)
#else
#define MEXPORT  __declspec(dllexport)
#endif

extern MEXPORT int* randomPointer;
extern MEXPORT void RandomFunction(int _int);



and in my cpp file...

   

MEXPORT int* randomPointer = NULL
MEXPORT void RandomFunction(int _int)
{
}

Now when i come to use these in my application, the function is fine. The compiler can find it, and use it. Same goes for all the class definitions too. But when i try to use the variable I get an undefined symbol linker error. I can remove that error by defining the variable _again_ in theapplication, bu tthis then means I have teo copies of the same variable flying about. I am using name spaces, but U have made sure, and the name spacing is correct, so I can count that out. Does anyone have any idea of what the problem might be and how to fix if? Thanks in advance Spree [Edit] On a side note, what exactly is the reason behind __declspec(dllimport)? I enable that, and all hell breaks lose! [edited by - SpreeTree on May 18, 2004 7:20:45 PM]

Share this post


Link to post
Share on other sites
Advertisement
Did you link your exe''s project against the .lib file produced by building the DLL project?

Share this post


Link to post
Share on other sites
quote:
Original post by SiCrane
Did you link your exe''s project against the .lib file produced by building the DLL project?


Yes, the lib is linked to. I removed it to see what happened, and all the other exported symbols came up as unresoved external symbols. I put it back, and again, just the variable is having trouble

Spree

Share this post


Link to post
Share on other sites
quote:
Original post by fyhuang
Isn''t your import/export macro reversed?


Yes its reversed, dont ask me why :s
But dllexport is being used, not dllimport

Spree

Share this post


Link to post
Share on other sites
The DLL:

DLL.h

#ifdef __DLL_EXPORTS__
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#endif

#include <windows.h>

extern "C" DLLAPI int iDllVar;
extern "C" DLLAPI void dllTest(void);


DLL.cpp
   
#ifndef __DLL_EXPORTS__
#define __DLL_EXPORTS__
#endif

#include "DLL.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;
}

DLLAPI void dllTest(void)
{
MessageBox(NULL, "dllTest()", "dllTest()", MB_OK);
}


The Program:

main.h
   
#ifndef __MAIN_H__
#define __MAIN_H__

#pragma comment(lib, "DLL.lib")

#include "Optimize.h"
#include "DLL.h"

#endif


main.cpp
   
#include "main.h"

int main(int argc, char *argv[])
{
iDllVar = 0;
dllTest();
return 0;
}


I'm pretty sure thats right

[edited by - Smacker_626 on May 18, 2004 7:43:27 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Smacker_626

I''m pretty sure thats right

[edited by - Smacker_626 on May 18, 2004 7:43:27 PM]


You havnt show in your code how you define the variable iDllVar? I added the "C" extern to the extern declaration, but still the same problem occured

Spree

Share this post


Link to post
Share on other sites

#ifdef __DLL_EXPORTS__
#define DLLAPI __declspec(dllexport)
#else
#define DLLAPI __declspec(dllimport)
#endif

#ifndef __DLL_H__
#define __DLL_H__

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

DLLAPI int iDllVar;
DLLAPI void dllTest(void);

#else /* __DLL_H__ */

extern "C" DLLAPI int iDllVar;
extern "C" DLLAPI void dllTest(void);

#endif /* __DLL_H__ */


sorry

EDIT: I hate the source tag

[edited by - Smacker_626 on May 18, 2004 8:09:27 PM]

Share this post


Link to post
Share on other sites
No, I am still getting the same unresolved symbol message.

I have even created an app which uses the dll created from the vc6 "A dll that exports some symbols", and even that application is gettong an unresolved symbol for the variables, but not the classes or functions.

The application I am using is a win32 console application started with void main(void). I can''t imagine this causeing any problems?

Spree

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!