Using FrontPanel DLL

Please ignore this first post… i fixed it and explained in in post 3

Sorry to keep posting all these newbie questions… but this is really frustrating :frowning:

I am usig VC++ 2005 express and FrontPanel 1.4.0

I followed the tutorial online for the DES example, except I am using the DLL API.

I copied okFrontPanelDLL.c and okFrontPanelDLL.h to my project directory and clicked on Add Existing Item… and added the two files. I also copied okFrontPanel.dll and okFrontPanel.lib to my proj directory. I then went to Properties->Linker->Input and added okFrontPanel.lib under Additional Dependencies.

In my code, I added #include “okFrontPanelDLL.h”

in the main function I have the following lines:

okUSBFRONTPANEL_HANDLE dev;

if (FALSE == okFrontPanelDLL_LoadLib()) {
printf(“Failed to load DLL.\n”);
}

for some reason, LoadLib() always returns false… meaning that the DLL is not being initialized.

Also, when compiling, I get this error in okFrontPanelDLL.c,

c:\documents and settings\evan park\my documents\visual studio 2005\projects\gui\gui\okfrontpaneldll.c(454) : warning C4133: ‘function’ : incompatible types - from ‘const char *’ to ‘LPCWSTR’

which is from the lines:

static DLL *
dll_load(const char *name)
{
#if defined(WIN32)
return((DLL *) LoadLibrary(name));

which is why the DLL is not loading properly i think… why is it giving me this error and how can i fix it???

Thanks in advance.

Evan

Also in okFrontPanel.dll, the following lines give me two errors:

okDLLEXPORT void DLL_ENTRY
okUsbFrontPanel_EnableAsynchronousTransfers(okUSBFRONTPANEL_HANDLE hnd, Bool enable)
{
if (_okUsbFrontPanel_EnableAsynchronousTransfers)
(*_okUsbFrontPanel_EnableAsynchronousTransfers)(hnd, (enable==TRUE)?(true):(false) );
}

the errors are:

c:\documents and settings\evan park\my documents\visual studio 2005\projects\gui\gui\okfrontpaneldll.c(953) : error C2065: ‘true’ : undeclared identifier
c:\documents and settings\evan park\my documents\visual studio 2005\projects\gui\gui\okfrontpaneldll.c(953) : error C2065: ‘false’ : undeclared identifier

just to follow up on my own questions:

i got rid of the DLL loading problem by changing the Character Set to Use Multi-Byte Character Set

and I got rid of the second problem by change (true) to 1 and (false) to 0
(but is this how i should fix it???)

HOWEVER, in the following code:

gotdevice:
// Get some general information about the XEM.
char str[128];
printf(“Device firmware version: %d.%d\n”,
okUsbFrontPanel_GetDeviceMajorVersion(dev),
okUsbFrontPanel_GetDeviceMinorVersion(dev));
okUsbFrontPanel_GetSerialNumber(dev, str);
printf(“Device serial number: %s\n”, str);
okUsbFrontPanel_GetDeviceID(dev, str);
printf(“Device device ID: %s\n”, str);

// Download the configuration file.
if (okCONFIG_NO_ERROR != okUsbFrontPanel_ConfigureFPGA(dev, DES_FPGA_CONFIGURATION_FILE)) {
	printf("FPGA configuration failed.\n");
	// We should deallocate the device object, but we won't bother.
	return(NULL);
}

// Check for FrontPanel support in the FPGA configuration.
if (okUsbFrontPanel_IsFrontPanelEnabled(dev))
	printf("FrontPanel support is enabled.\n");
else
	printf("FrontPanel support is not enabled.\n");

return(dev);

}

This line: if (okCONFIG_NO_ERROR != okUsbFrontPanel_ConfigureFPGA(dev, DES_FPGA_CONFIGURATION_FILE)) {

during compile gives the error: c:\documents and settings\evan park\my documents\visual studio 2005\projects\gui\gui\main.cpp(89) : error C2065: ‘okCONFIG_NO_ERROR’ : undeclared identifier

if i put if (false!= okUsb… it seems to load the bit file fine.

Is what I am doing normal? or am i missing something here? I got things to work but it just seems like I am changing too many things to make it work?

— Begin quote from evanichka

if (_okUsbFrontPanel_EnableAsynchronousTransfers)
    (*_okUsbFrontPanel_EnableAsynchronousTransfers)(hnd, (enable==TRUE)?(true):(false) );

}

— End quote

Evan –

This should be:

   if (_okUsbFrontPanel_EnableAsynchronousTransfers)
        (*_okUsbFrontPanel_EnableAsynchronousTransfers)(hnd, enable);
}

This was an error and has been fixed for the next release. Seems VS2005 is a bit more picky (rightly so) on the use of C++ types in a straight-C source file. We missed it when we built on VS2003.

Thanks!

Evan-

The okCONFIG_NO_ERROR should be okNO_ERROR.

Clearly, this sample does not even compile “out of the box” and I apologize for that – it apparently missed getting tested before release.

We have made the appropriate changes to the source and they will be included in the next release. Sorry for the trouble you encountered, but thanks for notifying us.

Thanks! Those lines did the trick.

I came across this problem during compilation as well.

[QUOTE]
for some reason, LoadLib() always returns false… meaning that the DLL is not being initialized.

Also, when compiling, I get this error in okFrontPanelDLL.c,

c:\documents and settings\evan park\my documents\visual studio 2005\projects\gui\gui\okfrontpaneldll.c(454) : warning C4133: ‘function’ : incompatible types - from ‘const char *’ to ‘LPCWSTR’[/QUOTE]

Changing the character set in project properties from Unicode to Multi Byte Character set did the trick.