PDA

Click to See Complete Forum and Search --> : DLL Problem Again!!! :(


Andreex
May 15th, 2002, 06:48 PM
I have been learning all the ways which you can create a DLL with VC++. The last time I learned how to do a DLL MFC. And when I tried to use it would send me an error. Somebody told me I had to copy the DLL to my debug folder of the VC++ test program. And it did work.

Now I have created a NORMAL dll. Which is quite different. Well... I am done with it. I created it with 0 error or wanrnings. I have my test VC++ program to use it. I added the lib file and also added the .h of the main dll class. I put it in the debug folder of the test program. Well... it tells me it doesnt recoginze the functions, the functions from the dll.


C:\Archivos de programa\Microsoft Visual Studio\MyProjects\p2\p2Doc.cpp(58) : error C2065: 'ModArtNewDrawing' : undeclared identifier

What in the world can it be wrong?:(

Wynd
May 15th, 2002, 07:13 PM
Are you including the .h file (the file with the function prototypes) in your main program?

Andreex
May 15th, 2002, 07:22 PM
Yes I am! :(

phinds
May 15th, 2002, 09:50 PM
sounds like you could be having a problem with name mangling

Zaei
May 16th, 2002, 08:05 AM
Are you exporting your functions from the DLL? For instance, do your function definitions look like this:

_API void myFunc();

or

__declspec(dllexport) void myFunc();

? If not, that could be your problem.

Are you using LoadLibrary()? If that is the case, you need a .def file. Lets say that you have a function, void X(). When compiling, this will become mangled, and GetProcAddress() wont find the function. You need to create a .def file with the name of your project, with the following lines in it:

LIBRARY MyLib
EXPORTS
X

Assume that your DLL will be called MyLib. The EXPORTS line says to export the following functions from the Library, as the Name specified. So, our X function will export as X, and not as it's mangled form. When using GetProcAddress, you then just specify X as the function to find.

Z.

Andreex
May 16th, 2002, 02:04 PM
this is an example of one of the dll functiona that i am exporting:



extern "C" void PASCAL EXPORT ModArtNewDrawing(CRect pRect, CObArray *poaLines)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

int lNumLines;
int lCurLine;

srand((unsigned)time(NULL));

lNumLines=rand()%50;

if (lNumLines>0)
{
for (lCurLine=0;lCurLine<lNumLines;lCurLine++)
{
NewLine(pRect, poaLines);
}
}
}


Then in the .def file I have this :


; DllNorm.def : Declares the module parameters for the DLL.

LIBRARY "DllNorm"
DESCRIPTION 'DllNorm Windows Dynamic Link Library'

EXPORTS
; Explicit exports can go here
ModArtNewDrawing
ModArtSerialize
ModArtDraw
ModArtClearDrawing



What do you think is wrong?

Zaei
May 17th, 2002, 08:20 AM
Originally posted by Andreex
this is an example of one of the dll functiona that i am exporting:



extern "C" void PASCAL EXPORT ModArtNewDrawing(CRect pRect, CObArray *poaLines)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

int lNumLines;
int lCurLine;

srand((unsigned)time(NULL));

lNumLines=rand()%50;

if (lNumLines>0)
{
for (lCurLine=0;lCurLine<lNumLines;lCurLine++)
{
NewLine(pRect, poaLines);
}
}
}


Then in the .def file I have this :


; DllNorm.def : Declares the module parameters for the DLL.

LIBRARY "DllNorm"
DESCRIPTION 'DllNorm Windows Dynamic Link Library'

EXPORTS
; Explicit exports can go here
ModArtNewDrawing
ModArtSerialize
ModArtDraw
ModArtClearDrawing



What do you think is wrong?

Change this:

extern "C" void PASCAL EXPORT ModArtNewDrawing(CRect pRect, CObArray *poaLines)

to this:

__declspec(dllexport) void ModArtNewDrawing(CRect pRect, CObArray *poaLines)

C++ makes DLL exporting easier. You also dont need the double quotes around your LIBRARY name.

Z.

Andreex
May 17th, 2002, 08:36 AM
Oh thank you! I am going to try that in a sec. Also... may ask what is the difference betweem how I had it and the way you are recommending me? THANKS A LOT!

CornedBee
May 24th, 2002, 08:32 AM
EXPORT is a #define that probably becomes export, which is a keyword that is deprecated in VC++6 and replaced by __declspec(dllexport)