我有一個C++文件,這是我在C#我打電話一些導出的函數。上述功能之一是這樣的:Windows已經引發了斷點由於堆損壞或DLL加載
char segexpc[MAX_SEG_LEN];
extern "C" QUERYSEGMENTATION_API char* fnsegc2Exported()
{
return segexpc2;
}
程序中某個位置,我也是做這件事:
if(cr1==1)
{
strcpy(segexpc, seg);
}
在我C#程序,我調用上述由followign方式:
[DllImport("QuerySegmentation.dll", EntryPoint = "fnsegcExported", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern StringBuilder fnsegcExported();
this.stringbuildervar = fnsegcExported();
以前,我沒有得到任何錯誤,但現在突然我開始收到此錯誤,當我在Visual Studio調試。
Windows has triggered a breakpoint in SampleAppGUI.exe.
This may be due to a corruption of the heap, which indicates a bug in SampleAppGUI.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while SampleAppGUI.exe has focus.
僅在之前它必須顯示窗口結束時會出現此錯誤。我沒有按下任何F12鍵,這裏也沒有設置任何斷點,但我不確定爲什麼錯誤在這裏出現並突破。 this.stringbuildervar = fnsegcExported();
當我按下繼續時,窗口顯示正確的輸出。
@jarika:我不完全熟悉C++,但我想知道,如果strcpy副本,直到「\ 0」。如果沒有,C++中是否有任何函數會自動複製目標字符串並將其作爲空字符串結束? – user1372448
strcpy將爲您添加空終止符(\ 0) '將由source指向的C字符串複製到目標指向的數組中,包括終止空字符' –