史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   VB與C++接軌 (http://forum.slime.com.tw/thread151921.html)

mini 2005-06-21 02:53 PM

VB與C++接軌
 
C++要寫 windows介面
整體來說 編寫時間上不如 VB 來的快的說

因此看說有人是...
用 C++(VC、BC) 寫運算 (.dll 為主)
用 VB 設計介面

但找到的都不是很完整
不知有無版友手上有完整範例的說

自己做過的努力如下
運行後是有顯示出 VC++的 MessageBox 內容
但接著就出現

執行階段錯誤'49':
DLL 呼叫格式錯誤

應該是指 參數傳遞 方面的錯誤
不知如何是好 ??

==VB==

Option Explicit
Private Declare Function ShowMsg Lib "test2.dll" Alias "ShowMsgW" (ByVal send As String, ByVal hWnd As Long) As Integer

Private Sub Command1_Click()
Dim send As String

send = "Hello,World!"
Call ShowMsg(send, Me.hWnd)

End Sub

==VC++==

..... //.....前面是專案精靈產生的程式碼,與試驗無關

extern "C" __declspec(dllexport) int ShowMsgW(LPCSTR pText, HWND hWnd)
{
return MessageBox(hWnd ,pText ,"Information" ,MB_OK);
}

====================

後來有想起
C++ 的 int 相當於 VB 的 long
因此
做過 ...(dllexport) int ShowMsgW ...
改成 ...(dllexport) short int ShowMsgW ...

或
ShowMsg Lib "test2.dll" ...(...) As Integer
改成
ShowMsg Lib "test2.dll" ...(...) As Long

結果亦然
(當然 改成不回傳值 void 也一樣,所以看來問題還是 參數傳遞 方面的錯誤)

mini 2005-06-22 02:58 PM

接著無奈下不管37 21
按下編譯 -> test.exe

執行(test.exe) 結果沒出現警訊
??
這次在 VB 上多加個除錯,變成

Option Explicit
Private Declare Function ShowMsg Lib "test2.dll" Alias "ShowMsgW" (ByVal send As String, ByVal hWnd As Long) As Integer

Private Sub Command1_Click()
Dim send As String
On Error GoTo NoDoThing

send = "Hello,World!"
Call ShowMsg(send, Me.hWnd)

Exit sub
NoDoThing:
MsgBox "Error"
End Sub

結果 VB 內就是先正確彈出 VC++的 MessageBox 內容
接著 彈出 VB的 "Error"

同樣 編譯成 test2.exe
執行
只得到 VC++的 MessageBox 內容

??
真是搞不懂,VB 內模擬 與 .exe 情況之差異


所有時間均為台北時間。現在的時間是 06:27 PM。

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2026, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1