11-14-2005 11:44 AM
11-14-2005 03:32 PM
Well I found som C++ code:
I define the functions of the subDLL to load in global.h:
typedef int (*tsubDllGetStatus) ();
typedef int (*tsubDllGetErrorMsg) (LPCSTR,int);
typedef int (*tsubDllInit) (LPCSTR,int,int);
In subDllLoader.h:
#pragma once
#include "globals.h"
extern tsubDLLInit subDllInit;
extern tsubDLLGetStatus subDllGetStatus;
extern tsubDLLGetErrorMsg subDllGetErrorMsg;
void UnLoadsubDll();
BOOL LoadsubDll();
BOOL IsLoadedsubDll();
In subDLLLoader.cpp
tsubDLLGetStatus subDLLGetStatus;
tsubDLLGetErrorMsg subDLLGetErrorMsg;
tsubDLLInit subDLLInit;
HINSTANCE hinstsubDLL = 0;
char szsubDLLLibName[80];
BOOL IsLoadedsubDll()
{
return (hinstsubDLL!=0);
}
void UnLoadsubDll()
{
if (hinstRPC)
{
FreeLibrary(hinstsubDLL);
hinstsubDLL = 0;
subDLLInit = NULL;
subDLLGetErrorMsg = NULL;
subDLLGetStatus = NULL;
};
}
void ErrorReport(const char* name,const char* what)
{
char szTemp[300];
_snprintf(szTemp,sizeof(szTemp)-1,"Error: %s, %s",what,name);
MessageBox(0,szTemp,szsubDLLLibName,MB_ICONEXCLAMATION | MB_OK);
}
HINSTANCE LoadLib(const char* name)
{
HINSTANCE h = LoadLibrary(name);
if (!h)
{
ErrorReport("Unable to load library","");
};
return h;
};
FARPROC GetProc(const char* name)
{
FARPROC fn = GetProcAddress(hinstsubDLL,name);
if (!fn) ErrorReport("GetProcAddress",name);
return fn;
};
#pragma warning(disable: 4706) //warning C4706: assignment within conditional expression
BOOL LoadsubDll()
{
UnLoadsubDll();
strncpy(szsubDLLLibName,sizeof(szsubDllLibName),"theDlltoLoad.dll");
// try to load the sub dll and setup function handles
if (!(hinstsubDLL = LoadLib(szsubDllLibName))) return FALSE;
TRACE ("Loaded %s!\n",szsubDllLibName);
if (!(subDllInit = (tsubDllInit) GetProc("Init"))) return FALSE;
if (!(subDllGetErrorMsg = (tsubDllGetErrorMsg) GetProc("GetErrorMsg"))) return FALSE;
if (!(subDllGetStatus = (tsubDllGetStatus) GetProc("GetStatus"))) return FALSE;
return TRUE;
}
then in your DLL you do:
if (!LoadsubDLL()) .... do error processing
int initstatus = subDllInit("string",0,0);
int status = subDllGetStatus();
....
unLoadsubDLL();
04-16-2006 07:04 AM
Hi,
I have the same problam with matlab dll's in labview. It runs once and the second time it crashes. I'm trying to use the c code in the newsgroup, but I get compilation errors like "undefined variable hintRPC" and a few other variables. Is there an include that I haven't written? Or is there some other reason for this problem? I'm using matlab 7, MSVC 6, labview 7.
Is there another way for labview to work with matlab dll's twice?
Thanks!
07-05-2006 12:56 PM
03-18-2008 10:24 PM
I am fighting the same issue with the intialize and terminate. Did you ever get it to work?
John
03-20-2008 06:50 AM
Hi John,
Using the MathScript Node may be another option for you. More information can be found here as well.
03-20-2008 11:05 AM
03-24-2008 12:48 PM
03-25-2008 07:03 AM
Thanks, but the machine that it will be deployed on will not have MATLAB.
There is some hope with dynamically loading the dll using an empty path to the call library function vi.
03-26-2008 03:26 PM
Hi,
My solution was to split the function into three: "init", "runFunction", and "terminate". At the beginning of the program I run "init"; when the user quits I run "terminate". During the program "runFunction" is executed every time user presses the doFunction button.
Good luck!
Danielle