Unable to call function in DLL

 
Hi,

Please ignore my previous post, I just found the sample exampledll.cpp file and made an example appropriately.

When I try to reference my DLL on MT 4 build 184, i get a

2005.11.05 23:43:46 printme USDCHF,M1: cannot call function 'ShowMe' from dll 'Printme2.dll'

I am only testing and I have a simple DLL that I am compiling in Visual C++ .NET 2003. Here is my simple source code:

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

#define MT4_EXPFUNC __declspec(dllexport)

#pragma pack(push,1)
struct RateInfo
{
unsigned int ctm;
double open;
double low;
double high;
double close;
double vol;
};
#pragma pack(pop)

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;
}

MT4_EXPFUNC double __stdcall ShowMe(const double myNum)
{
printf("Number passed to me is: %d\n", myNum);
return(myNum);
}

Is there something that I am doing wrong?

Thanks

Mike
 
With __stdcall Windows decorates the call names with information about the parameters, e.g. yours would get _ShowMe@4

You might want to try to import it with that name or create a .def file for your library with a command like
ShowMe=_ShowMe@4

to export the function under the undecorated name.


I'm not entirely sure about the syntax but it should be something like:

PRINTME2.DEF
LIBRARY PRINTME2

EXPORTS
          ShowMe="_ShowMe@4"




Markus

 
Thanks Markus, I just tried it and it works. I didnt have the .def file.


Thanks again!

Mike
 
Glad to have been of help.

Btw, Functions with more parameters would have different decoration. Mostly the number after the "@" is the number of parameters multiplied with 4, but you can also look at the .map file which the linker creates to find out the exact name.


Markus
Reason: