- - PR -
VB.NETからVC++で作成したDLLの呼び出し
1
投稿者 | 投稿内容 | ||||
---|---|---|---|---|---|
|
投稿日時: 2005-01-31 20:45
O-Nadegataと申します。
VC++で作成したDLLをVB.NETで呼び出すところでつまずいています。 制御はDLL側に移っているのですが、パラメータがうまく渡っていない ようです。 以下がDLL側のメソッド定義です。 ----------------------------- int methodA( float line, UINT size, char *BarCode, UINT PortNo, DWORD BaudRate, BYTE StopBits, BYTE Parity, BYTE ByteSize ) ----------------------------- VB.NETでは以下のように呼び出しています ----------------------------- '宣言部分 Private Declare Function methodA Lib "AAAAA.dll" ( _ ByVal Line As Single, _ ByVal size As System.UInt32, _ <MarshalAs(UnmanagedType.LPStr)> ByVal Barcode As String, _ ByVal PortNo As System.UInt32, _ ByVal BaudRate As System.UInt32, _ ByVal StopBits As System.Byte, _ ByVal Parity As System.Byte, _ ByVal ByteSize As System.Byte) As Integer '呼び出し部分 Dim lngRet As Integer = 0 Dim strBarcode As String Dim line As Single = Single.Parse("1", Globalization.NumberStyles.Float) Dim size As System.UInt32 = System.UInt32.Parse("14") Dim portNo As System.UInt32 = System.UInt32.Parse("1") Dim bRate As System.UInt32 = System.UInt32.Parse("9600") Dim StopBits As System.Byte = System.Byte.Parse("0") Dim Parity As System.Byte = System.Byte.Parse("0") Dim ByteSize As System.Byte = System.Byte.Parse("8") lngRet = methodA (line, _ size, _ strBarcode, _ portNo, _ bRate, _ StopBits, _ Parity, _ ByteSize) ----------------------------- VB.NETの型がVC++の型にうまくはまっていない のだと思います。 (おそらく「float line」がうまく渡っていない じゃないかなと・・・) 何か分かる事があればご教授お願いいたします。 | ||||
|
投稿日時: 2005-01-31 22:06
例外は発生していないのですか? 具体的に、どのパラメータが、指定した値と異なっていますか? DLL 関数の呼び出し規約を明示的に指定しても状況に変化はありませんか? _________________ // 渋木宏明 (Hiroaki SHIBUKI) // http://hidori.jp/ // Microsoft MVP for Visual C# // // @IT会議室 RSS 配信中: http://hidori.jp/rss/atmarkIT/ | ||||
|
投稿日時: 2005-02-01 22:02
すみません。解決してしまいました。
宣言部 ------------------------------------------ Private Declare Ansi Function methodA Lib "M6654HB.dll" _ (ByVal Line As System.Single, _ ByVal size As System.UInt32, _ ByVal Barcode As System.Text.StringBuilder, _ ByVal PortNo As System.UInt32, _ ByVal BaudRate As System.UInt32, _ ByVal StopBits As System.Byte, _ ByVal Parity As System.Byte, _ ByVal ByteSize As System.Byte) As System.Int32 ------------------------------------------ ↑ 第3引数をStringからStringBuilderに変えた。 もう少し調べてから書き込むべきでした。 渋木宏明(ひどり)さん御回答ありがとうございました。 ちなみに、下記ページを参考にしました。 http://dobon.net/vb/bbs/log3-5/2802.html |
1