#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]
Exporting variables from a dll issue
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 )
Did you link your exe''s project against the .lib file produced by building the DLL project?
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
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
The DLL:
DLL.h
DLL.cpp
The Program:
main.h
main.cpp
I'm pretty sure thats right
[edited by - Smacker_626 on May 18, 2004 7:43:27 PM]
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]
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
#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]
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement