【发布时间】:2014-02-07 11:36:34
【问题描述】:
我有以下代码
System::Void MainForm::initLoadCell(){
//Open the first found LabJack U3 over USB.
lngErrorcode = OpenLabJack (LJ_dtU3, LJ_ctUSB, "1", TRUE, &lngHandle);
//Load defualt config
lngErrorcode = ePut (lngHandle, LJ_ioPIN_CONFIGURATION_RESET, 0, 0, 0);
//Setup FIO0 as an analogue input port
lngErrorcode = ePut (lngHandle, LJ_ioPUT_ANALOG_ENABLE_BIT,0,1,0);
//Obtain error string
char* errorcode = new char;
ErrorToString(lngErrorcode, errorcode);
// Convert the c string to a managed String.
String ^ errorString = Marshal::PtrToStringAnsi((IntPtr) (char *) errorcode);
MainForm::textBox_LoadCellError->Text = errorString;
Marshal::FreeHGlobal((IntPtr)errorcode);
}
这在我直接从 Visual Studio 运行程序时有效,但是当我构建 .exe 文件并作为独立运行时,我收到以下错误
Problem signature:
Problem Event Name: APPCRASH
Application Name: BenchTester.exe
Application Version: 0.0.0.0
Application Timestamp: 52f4c0dd
Fault Module Name: ntdll.dll
Fault Module Version: 6.1.7601.18247
Fault Module Timestamp: 521ea8e7
Exception Code: c0000005
Exception Offset: 0002e3be
OS Version: 6.1.7601.2.1.0.256.1
Locale ID: 3081
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409
If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt
我知道是下面这行引起的
ErrorToString(lngErrorcode, errorcode);
这是对第 3 方代码的调用,我认为错误与未正确处理非托管代码的代码有关,但我不确定在哪里。有人可以指出我正确的方向。
【问题讨论】:
标签: .net c++-cli unmanaged managed