我遇到以下問題。 我使用以下函數從緩衝區接收字符串,直到出現換行符。C++ Dll字符串函數崩潰
string get_all_buf(int sock) {
int n = 1, total = 0, found = 0;
char c;
char temp[1024*1024];
string antw = "";
while (!found) {
n = recv(sock, &temp[total], sizeof(temp) - total - 1, 0);
if (n == -1) {
break;
}
total += n;
temp[total] = '\0';
found = (strchr(temp, '\n') != 0);
if (found == 0){
found = (strchr(temp, '\r\n') != 0);
}
}
antw = temp;
size_t foundIndex = antw.find("\r\n");
if (foundIndex != antw.npos)
antw.erase (antw.find ("\r\n"), 2);
foundIndex = antw.find("\n");
if (foundIndex != antw.npos)
antw.erase (antw.find ("\n"), 2);
return answ;
}
因此,使用這樣的:
string an = get_all_buf(sClient);
如果我創建一個EXE文件的一切完美的作品。 但是,如果我創建了一個DLL和使用RUNDLL32應用程序關閉在「string an = get_all_buf(sClient);
」沒有任何錯誤信息運行...
我想現在就解決這個問題了幾個小時,我現在有點絕望...
PS對於明顯的錯誤或錯誤的編碼風格感到抱歉,我剛開始學習C++。
你爲什麼要用rundll32.exe來運行它?除此之外你還沒有任何環境,不是嗎?在VS中構建一個C++項目並鏈接到您的DLL。 – 2013-03-01 10:54:33
你還可以包含你從rundll32的命令行運行的* proc *,它最終會調用它嗎?這可能很重要。除此之外,請參閱simon的答案,因爲您的猜測與我的rundll32用於默認堆棧大小(可能恰好爲1MB,因此您應該dyna-分配該臨時緩衝區)一樣好。 – WhozCraig 2013-03-01 10:57:26