LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a pointer to an array of pointers to a DLL

Hi all!

 

I am trying to pass a pointer to an array of pointers from my main application to a DLL through a static library.  Everything seems to work up to the point where the DLL function is called, and once the DLL tries to pull in the reference to the array, it instead pulls in the value of the first element of the array, which messes everything up inside the DLL.  My sample code is below:

 

 

FROM THE MAIN FUNCTION:

 

void CVICALLBACK CB_INSTRUMENT_CONFIG (int menuBar, int menuItem, void *callbackData, int panel)
{
char MAX_COUNT_str[MAX_COUNT/1024];
char parentPanelHandle_str[MAX_COUNT/1024];

snprintf (MAX_COUNT_str, sizeof (MAX_COUNT_str), "%i", MAX_COUNT);
snprintf (parentPanelHandle_str, sizeof (parentPanelHandle_str), "%i", parentPanelHandle);

char *argv[] = {WorkingDir, MAX_COUNT_str, apiRTFileName, parentPanelHandle_str};
DLL_LOAD_FUNCTION (LibDir, "Instrument Configuration.dll", "InitUIForDLL", argv);
}

 

FROM THE STATIC LIBRARY FUNCTION "DLL_LOAD_FUNCTION":

int DLL_LOAD_FUNCTION (char* LibDir, char* LibName, char* FuncName, char *argv[])
{
typedef int (*MYPROC)(char**);
HINSTANCE hinstLib; //Handle to the DLL
MYPROC ProcAddress; //Pointer to the function
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
char LibPathandName[512] = "\n";
int returnValue;
char UserMsg[512];

snprintf (LibPathandName, sizeof (LibPathandName), "%s\\%s", LibDir, LibName);
hinstLib = LoadLibrary(LibPathandName);

if (hinstLib != NULL)
{
ProcAddress = (MYPROC) GetProcAddress(hinstLib, FuncName);

if (fRunTimeLinkSuccess = (ProcAddress != NULL))
{
returnValue = (ProcAddress)(argv);
fFreeResult = FreeLibrary(hinstLib);
}

else
{
snprintf (UserMsg, sizeof (UserMsg), "Unable to get Address of Function \"%s\" from Library file \"%s\".\n\nCheck name of function and prototype in header file.", FuncName, LibName);
MessagePopup("ERROR!", UserMsg);
}
}

else
{
snprintf (UserMsg, sizeof (UserMsg), "Unable to locate Library file \"%s\" in:\n%s", LibName, LibDir);
MessagePopup("ERROR!", UserMsg);
}

return 0;
}

 

FROM THE DLL "Instrument Configuration.dll":

int InitUIForDLL (char *arginv[])
{
MAX_COUNT_LOCAL = atoi(arginv[1]);
char apiRTFileName [MAX_COUNT_LOCAL/16];

strncpy (WorkingDir_LOCAL, arginv, sizeof (WorkingDir_LOCAL));
strncpy (apiRTFileName, arginv, sizeof (apiRTFileName));

.

.

.

}

 

When I run this code, arginv in "Instrument Configuration.dll" ends up being the first pointer value in the argv array.  I've tried adding references and de-references all over the place to no avail.  What am I doing wrong? 

 

(Disclaimer: I have basically learned C all by doing, examples, and help files, so I am by no means good at it Smiley Wink)

0 Kudos
Message 1 of 1
(4,110 Views)