當它運行的程序工作正常,但是當我嘗試步驟通過它,我得到的只是得到一個異常#1在未知模塊「。我通過程序步進當
下面是代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace PInvokeTest
{
class Program
{
static void Main(string[] args)
{
int session_handle = 0;
int flag = 0;
int didsetup = 0;
int defPort = 0;
int i = 0, j = -1;
short[] ROM;
ROM = new short[9];
short type_test = 0;
short port_num = 0, port_type = 1;
byte[] state_buf = new byte[5125];
StringBuilder ID_buf = new StringBuilder();
StringBuilder serial = new StringBuilder();
StringBuilder serialtmp = new StringBuilder();
//Finds default device type and port
defPort = TMReadDefaultPort(out port_num, out port_type);
// get the TMEX driver version
Get_Version(ID_buf); // STACKOVERFLOW EXCEPTION HERE
...
Console.ReadKey();
}
[DllImport("IBFS32.dll")]
public static extern int TMExtendedStartSession(
short PortNum,
short PortType,
IntPtr EnhancedOptions
);
[DllImport("IBFS32.dll")]
public static extern short TMReadDefaultPort(
out short port_num,
out short port_type
);
[DllImport("IBFS32.dll")]
public static extern short Get_Version(
[MarshalAs(UnmanagedType.LPStr)]StringBuilder ID_buf
);
[DllImport("IBFS32.dll")]
public static extern short TMGetTypeVersion(
short port_type,
[MarshalAs(UnmanagedType.LPStr)]StringBuilder ID_buf
);
[DllImport("IBFS32.dll")]
public static extern short TMSetup(
int session_handle
);
[DllImport("IBFS32.dll")]
public static extern short TMNext(
int session_handle,
byte[] state_buf
);
[DllImport("IBFS32.dll")]
public static extern short TMRom(
int session_handle,
byte[] state_buf,
short[] ROM
);
[DllImport("IBFS32.dll")]
public static extern short TMEndSession(
int session_handle
);
}
}
會是什麼導致只有工作的時候,你不踩運行呢? 我有另一個程序使用非常相似的代碼(dll函數在不同的類中),但它會得到一個stackoverflow異常,無論它如何運行。
編輯:
當我使用這個DLL的64位版本和64位在建立我的程序,它工作正常,所有的時間......我不知道這些信息對你的幫助雖然。
我需要運行32位版本。
你得到一個堆棧跟蹤?經常出現SO錯誤,您可以確定軌跡中的循環,這通常非常有用。 – Gus
我不相信我會得到一個,它會在拋出異常時彈出的消息窗口中說出來嗎? – user3232337
如果您在步入時處於Visual Studio中,則異常窗口可能有辦法解決。根據VS的版本,您可能需要先點擊「Details」,然後通常是「Call Stack」或「Exception Trace」。 – Gus