Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

LV crashes calling a dll

Hi guys,

 

I have written a C function in VS 2010 and then changed it into dll. This is that function before transforming into dll:

 

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

extern "C"  _declspec(dllexport) extern "C" _declspec(dllexport) int Train(int numOfTrials,
                                                                          int numPerTrial,
                                                                          int numOfCommands,
                                                                          double* Data_in,
                                                                          double* b_in,
                                                                          double* bB_in,
                                                                          double* gmeans1_out,
                                                                          double* gmeans2l_out,
                                                                          double* gmeans2r_out);
void PrintMatrix(CvMat *Matrix,int Rows,int Cols);

extern "C" _declspec(dllexport) int Train(int numOfTrials,
                                          int numPerTrial,
                                          int numOfCommands,
                                          double* Data_in,
                                          double* b_in,
                                          double* bB_in,
                                          double* gmeans1_out,
                                          double* gmeans2l_out,
                                          double* gmeans2r_out)
{ the body of the function...

return 1;

}

 

I created a dll by running this dll application type project in release mode. the problem is that when I run the LV with this dll implemented in it it crashes without giving me any error or a clue. I know that this can happen when the memory allocating in LV does not match the ones used in the function. I've checked and rechecked I don't have that problem. Therefore, I'm looking for a solution here to give me a clue of what is wrong that causes the LV to crash itself.

 

Thank you for your help,

Elnaz

 

0 Kudos
Message 1 of 2
(5,494 Views)

Hi Elanz,

 

Does LabVIEW generate an error log when you open it up again? We might be able to make use of the error log to determine what's causing LabVIEW to terminate. Additionally, have you tested the dll in other environments? I'd recommend that you try calling the dll in C while monitoring memory usage and with an attached debugger to verify that the issue isn't with the dll.

 

You can also set a token in the LabVIEW INI file to allow for immediate reporting of DWarn Errors by adding the line: "DWarnDialog = TRUE". If a DWarn error is thrown prior to the crash, this method will allow you to catch whatever is causing LabVIEW to terminate.

 

As a sanity check, try using built in dlls (such as system dlls found in the System32 folder in Windows). If you are able to successfully call into these other dlls, the problem is likely with the dll that you've written.

Sanjay C.
Embedded Software Product Manager| National Instruments
0 Kudos
Message 2 of 2
(5,464 Views)