0

I'm new at programing in C/C++, and although I've looked in Microsoft's help and in other StackOverflow questions I haven't found the answer to my problem.

I am trying to call an exported function from a DLL I made in Visual Studio 2008. This DLL it's called from a VBA macro and from an user interface program made in LabWindows/CVI. It works fine with the VBA macro, however the program in LabWindows crashes when I try to load it.

I tried both, statically and dynamically calling. Here's what I have:

The function in the DLL is exported in this way, _stdcall so VBA can use it and __declspec( dllexport ) to get rid of the .def file.

__declspec( dllexport ) double * __stdcall calculos( char * String_inputs);

The input string is a really long array of chars. It's a way of passing +60 strings (each string separated by a comma ","). Then in the code they are divided by strtok using the comma (",") as reference. This is necesary as the input limit of VBA in a function is 60.


When I try to call the function statically (adding the .lib file and the header of the DLL to the project) I get the following error.

error: Undefined symbol '_calculos@4' referenced in "c:\PATH\cvibuild.PROJECTNAME\Debug\Main.obj". 

The code of the static calling is the following:

double * array_out; //Pointer to array of double      
         array_out = calculos(STRING_INPUT);

I tried calling the function with his decorated name, but it doesn't work.

array_out = _calculos@4(STRING_INPUT);

When I checked on DependencyWalker the name of the function I get this name:

?calculos@@YGPANPAD@Z

I tried using it too on the function calling and definition without success.

What I'm doing wrong?


When I try to call the function dynamically the program crashes. The DLL, the header file and the .lib are placed in the project folder.

    typedef double * (*DLLFUNC)(char*); //DLL function prototype 
    HINSTANCE hinstLib; //Handle to the DLL
    DLLFUNC ProcAddress; //Pointer to the function

    hinstLib = LoadLibrary("General.dll");

    //The the pointer to the exported function and typecast it so that we can easily call it
    //DLLFUNC is typedef'ed above
    ProcAddress = (DLLFUNC) GetProcAddress(hinstLib, "?calculos@@YGPANPAD@Z"); 

    //Call the function using the function pointer
    double * array_out = ProcAddress(STRING_INPUT); //It crashes here

When I debug the program when it crashes I find that the commas (",") in my char * are replaced with '\0', so only the first string gets to the DLL. That may be the reason, but I just don't know why the commas (",") are replaced.

I've also tried calling it with the decorated names, without success.

ProcAddress = (DLLFUNC) GetProcAddress(hinstLib, "_calculos@4");//Error -> Dereference to null pointer
ProcAddress = (DLLFUNC) GetProcAddress(hinstLib, "calculos"); //Error -> Dereference to null pointer
D.García
  • 1
  • 2
  • What exactly is `STRING_INPUT`? Note that `strtok` changes the string, so if the parameter is in fact a `const char*`, this could be a problem – Karsten Koop May 18 '16 at 13:49
  • @KarstenKoop STRING_INPUT is a array of char [300]. It's formed with a FOR loop and it has this structure --> "STRING1,STRING2,STRING3,..." The value of the STRINGx depends on the inputs of the program. – D.García May 19 '16 at 08:18

0 Answers0