我正在嘗試使用C++ dll編寫簡單的擴展存儲過程來將一些文本寫入控制檯。我在接下來的方式進行的:爲什麼我的C++擴展存儲過程不能寫入控制檯?
- 創建使用C++(看的.cpp及以下.h文件)
- 測試從Win32控制檯應用程序此DLL(所有的工作抽動德趾) 一個dll
- 舉動得到了dll文件到SQL Server的bin目錄
- 從管理工作室執行
sp_addextendedproc 'xp_test','xp_test.dll'
- 執行擴展PROC(
exec xp_test
)
當我執行了最後一步時,出現一個提示,通知我查詢被匆匆執行,但沒有任何具有預期的hello world提示符的控制檯窗口。我的錯在哪裏?
//test.h file
#ifdef MYLIBAPI
#else
#define MYLIBAPI extern "C" __declspec(dllimport)
#endif
#include <srv.h>
MYLIBAPI SRVRETCODE xp_test(SRV_PROC *srvproc);
// xp_test.cpp : Defines the exported functions for the DLL application.
#include "stdafx.h"
#define MYLIBAPI extern "C" __declspec(dllexport)
#include "test.h"
#include <iostream>
using namespace std;
SRVRETCODE xp_test(SRV_PROC *srvproc){
cout << "Hello world" << endl;
cin.get();
return 0;
}
我也試圖使用控制檯API但這也不允許寫安慰
SRVRETCODE xp_test(SRV_PROC *srvproc){
AllocConsole();
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD writtenCount;
LPCTSTR msg = L"Hello world\n";
WriteConsole(out, msg, lstrlen(msg), &writtenCount, NULL);
Sleep(5000);
return 0;
}
你使用什麼編譯器?這可能是一個依賴性問題,請確保所有內容都靜態鏈接到您的程序中。 – demorge 2013-05-03 17:28:43
@demorge VS 2010終極版 – user2201747 2013-05-03 17:35:04
試試這個:項目屬性頁面 - >配置道具 - > C/C++ - >代碼生成 - >運行時庫 - >現在選擇那些無w/o DLL進行調試和發佈。 – demorge 2013-05-03 17:38:13