From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with DLL calling from LabView

Hi, all.

 

I want to call several functions compiled into a dll. The function prototype of one of them is this:

 

BOOL Initialize (char *configFile, char *coordFile, int &id);

 

 

To export the function, I use the following declaration:

 

extern "C" BOOL __declspec( dllexport ) Initialize (char *configFile, char *coordFile, int &id)

 

 

I use the Call Library Function Node. The entry points are correctly detected and I can select the name of this function within the dll. Then, I set the following parameters types:

 

return type:  signed 8-bit Integer

arg1:  C String Pointer

arg2:  C String Pointer

arg3:  Signed 32-bit Integer (pass by value)

 

 

When I run the VI, I get the following error message:

 

"Error 1097 occurred at Call Library Function Node. Possible reason(s):

LabVIEW:  An exception occurred within the external code called by a Call Library Function Node. The exception may have corrupted LabVIEW's memory. Save any work to a new location and restart LabVIEW."

 

 

The function Initialize deals with opening several dialog boxes and introducing information into them. Could this have caused this error?

 

Thanks in advance,

Francisco.

 

 

0 Kudos
Message 1 of 12
(3,748 Views)
BOOL is most likely a 32-bit integer, so you should change the return type to I32. At least it is if you're referring to the BOOL defined in the standard Windows header files. What did you set the calling convention to? I assume you left it as "C"? Does the DLL try to update those character pointers?
Message Edited by smercurio_fc on 11-09-2009 01:13 PM
0 Kudos
Message 2 of 12
(3,731 Views)

Hi

 

I also faced the same problem, my problem was that i was using the wrong calling convention. Add _stdcall in your declaration and use the standard calling convention in labview. It may work.

 

For your guidance just write "Error 1097 in call library function" in the search box. I am sure that this thread will help you.

 

Regards

 

mhs100 

0 Kudos
Message 3 of 12
(3,726 Views)

Hi, thanks for your fast reply.

 

At first, I was using C calling convention. Well, I've tried setting the return type to I32, adding __stdcall to the declaration and changing the calling convention (stdcall), but nothing new. The error remains. smercurio_fc, I think the character pointers are not updated (I don't really know, because I'm not the dll programmer, but I'm going to ask).

 

The dll's source code has been implemented using MFC. Maybe is there any kind of incompatibility between this library and LabView?

 

Thanks again,

Francisco

0 Kudos
Message 4 of 12
(3,703 Views)
I'm a little confused. If you're not the DLL programmer, then how are you changing the calling method within the DLL?
0 Kudos
Message 5 of 12
(3,697 Views)
Good question, smercurio_fc, hehe.

Well, I work on the LabView part but I'm in contact with the dll programmer and tell him the requirements that the source code has to match in order to be called from LabView.
0 Kudos
Message 6 of 12
(3,691 Views)

If you can mandate input/output data type, then change &id to *id:

 

_declspec (dllexport) BOOL Initial(char *configFile, char *coorFile, int *id);

 

 

see attached dll/VI.

 

 

George Zou

http://webspace.webring.com/people/og/gtoolbox/

 

George Zou
Download All
0 Kudos
Message 7 of 12
(3,669 Views)

Hello, Zou, thanks for your support.

First of all, I can't load your VI file because it's LV 9.0. Mine is LV 8.6. Could you please send me a compatible version?

Then, I created a simple VI with a Call Library Function Node and I tried to compile your C code to a dll, but I think I'm doing something wrong, because I get the same problem when trying to call it from LabView. At first, I get an empty validation window, then I press "OK", and the same error appears: "Error 1097 occurred at Call Library Function Node... "

However, I'm not sure about the correct procedure to get the dll in Microsoft Visual C++. How can I define the entry point? Is there no need to include the following piece of code? (because I only can see  in your file a DllMain function but is not declared in the same way):


// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

BOOL APIENTRY DllMain( HMODULE 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;
}

 

 

Thanks,

Francisco

Mensaje editado por Porras
Mensaje editado por Porras
0 Kudos
Message 8 of 12
(3,656 Views)

#include "stdafx.h"

BOOL APIENTRY DllMain( HMODULE 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;
}

Francisco,

 

Unless you want add some code in each case, otherwise you don't need them.

 

VI in LV8.6 is attached.

 

 

George Zou

http://webspace.webring.com/people/og/gtoolbox/

George Zou
0 Kudos
Message 9 of 12
(3,648 Views)

It's OK. Zou, your example works totally correct. So it's not a problem with LabView configuration or the way of calling the DLL (the VI I was using was identical).

 

So, the problem is in the DLL, then:

 

- Are there any aditional needs to compile the DLL when using MFC Class Library?

 

- Maybe, could be any incompatibility between DLL libraries using MFC which are not properly compiled and LabView? (I mean, if I am going to use a C++ function that uses MFC, do I have to compile it into a DLL in a different way unlike the procedure shown here, adding some extra code in DllMain or declaration, in order to be used in LabView?)

 

Thanks again,

Francisco

Mensaje editado por Porras
Mensaje editado por Porras
Mensaje editado por Porras
0 Kudos
Message 10 of 12
(3,640 Views)