|
|
|
|||||
|
Ice in a DLL fails unexpectedly?
Okay, I'm trying to interface LabVIEW to the Ice protocol. The best way I can find to do this is to write a DLL, which LabVIEW can then load and call the functions. So, I've written up a simple DLL with one function that basically just encapsulates the simplePrinter example.
LabIce_DLL1.h: Code:
__declspec(dllexport) void __stdcall LabIce_PrintLong(unsigned long pnum); Code:
#include "stdafx.h"
#include "LabIce_DLL1.h"
#include "Printer.h"
#include "C:\Ice-3.1.0\include\Ice\Ice.h"
using namespace std;
using namespace Demo;
__declspec(dllexport) void __stdcall LabIce_PrintLong(unsigned long pnum)
{
bool ierr = false;
try{
Ice::CommunicatorPtr ic;
Ice::ObjectPrx base;
PrinterPrx printer;
//emulate command line parameters
char* argv[] = {"gdao"};
int argc = 1;
//no error yet
ierr = false;
ic = Ice::initialize(argc, argv);
//base = ic->stringToProxy("SimplePrinter:default -p 10000");
//printer = PrinterPrx::checkedCast(base);
//if (!printer)
// ierr = true;
//printer->printLong( ((Ice::Long)(pnum)) );
if(ic)
ic->destroy();
} catch(...) {
//ierr = true;
}
//return !ierr;
}
Does anyone have any idea what it might be?
__________________
Daniel Dunn Miltec Systems NASA Engineering, Science, and Technology Support (ESTS) Contract |
|
|||||
|
Ah, so native exceptions wouldn't be caught? That could be it then.
Also, I know that it would be expensive to do that, this is just a test. I originally tried putting them in the DLL's global space, but I wasn't sure if that was causing the error. Unfortunately, I have a kind of chicken-and-egg problem in doing that with LabVIEW, because I'd first have to compile the labview project to an executable. And in order to do that, the DLL would have to work. (I think) I'll see what I can do, though. Thanks for the pointers.
__________________
Daniel Dunn Miltec Systems NASA Engineering, Science, and Technology Support (ESTS) Contract |
|
|||||
|
Okay, now I at least have a new angle on the problem. I finally got a test program constructed that does nothing but call the function. I ran it in debug mode and got an 'access violation' error. I have a nagging suspicion that that has something to do with multithreading. If that's the case, what did I do wrong?
Exception: Code:
Unhandled exception at 0x00000000 in TestApp.exe: 0xC0000005: Access violation reading location 0x00000000. Code:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
int _tmain(int argc, _TCHAR* argv[])
{
/* get handle to dll */
HINSTANCE hGetProcIDDLL = LoadLibrary((LPCWSTR)"D:\\Coding\\C++ Projects\\LabIce_DLL1\\debug\\LabIce_DLL1.dll");
/* get pointer to the function in the dll*/
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), "LabIce_PrintLong");
/*
Define the Function in the DLL for reuse. This is just prototyping
the dll's function. A mock of it. Use "stdcall" for maximum
compatibility.
*/
typedef void (__stdcall * pICFUNC)(unsigned long);
pICFUNC LPrintLong;
LPrintLong = pICFUNC(lpfnGetProcessID);
/* The actual call to the function contained in the dll */
LPrintLong((unsigned long)200);
/* Release the Dll */
FreeLibrary(hGetProcIDDLL);
}
__________________
Daniel Dunn Miltec Systems NASA Engineering, Science, and Technology Support (ESTS) Contract |
|
||||||
|
That access violation message usually indicates that your program is dereferencing a null pointer. For example, your program calls GetProcAddress and then dereferences the return value without checking whether it is NULL. If you're confident that the access violation occurs inside your function, I recommend building everything in debug mode with multi-threading enabled and run it in the debugger to get a stack trace.
Take care, - Mark |
|
|||||
|
After looking at the debugger, that actually *didn't* have to do with the DLL. Some sort of weird string conversion needs to be done to the pathname to load it. I'll let you know if/when I get an actual debug from the DLL.
__________________
Daniel Dunn Miltec Systems NASA Engineering, Science, and Technology Support (ESTS) Contract |
|
|||||
|
Okay, I finally called it out. (I also had name mangling problems)
But now, I get this inside the DLL, when calling Ice::initialize(argc,argv) Exception: Code:
Unhandled exception at 0x00439e92 in TestApp.exe: 0xC0000005: Access violation reading location 0xccccccd0. I do know that all of the other DLLs needed are present, but I can't tell you much beyond that. Is there any information I can post from the debugger that would tell you anything?
__________________
Daniel Dunn Miltec Systems NASA Engineering, Science, and Technology Support (ESTS) Contract |
|
||||||
|
In many cases, such problems are caused by mixing debug and release libraries. Have a look at this FAQ for more information.
|
|
|||||
|
Yeah, just stumbled across that a moment ago. I'm working it right now...
__________________
Daniel Dunn Miltec Systems NASA Engineering, Science, and Technology Support (ESTS) Contract |
|
|||||
|
That seems to have fixed the problem! Thanks!
![]()
__________________
Daniel Dunn Miltec Systems NASA Engineering, Science, and Technology Support (ESTS) Contract |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IcePy 2.0.0 fails, hangs on Mac OS X 10.3 | Michael Halle | Bug Reports | 1 | 11-30-2004 11:07 AM |
| ice_checkedCast fails | griffima | Help Center | 2 | 10-19-2004 09:42 AM |
| demo build fails in prebuild | dlyall | Bug Reports | 1 | 09-02-2004 07:47 PM |
| Slice test fails | marlowa | Bug Reports | 3 | 02-20-2003 10:16 AM |