vb.net调用非托管函数aa.dll,aa.dll包括2个入参数,2个出参数。请教怎么调用?解决送100分

qiri07 2005-06-22 09:11:20
在VC++中调用
定义 int GetContent(IN char* lpszURL, IN char* lpszSubject, OUT char* lpszPushContent, OUT int &nTotalPacket);
调用 int rc = GetContent((char *)(LPCTSTR)m_strURL, (char *)(LPCTSTR)m_strSubject, szContent, nPacketCount);

在VB.net中如何调用???
------------------------------------
本人试验

<DllImport("aa.DLL", EntryPoint:="GetContent", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> Public Shared Function GetContents(ByVal src As String, ByVal dst As String, ByVal contents As String, ByVal intpage As Integer) As Integer
' Leave function empty - DllImport attribute forces calls
End Function

调用时 RetVal = GetContents(sendurl.Text, sendtext.Text, contents, intpage)

提示:调用行 :未将对象引用设置到对象的实例。
------------------------------------------
如果这样
<DllImport("aa.DLL", EntryPoint:="GetContent", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> Public Shared Function GetContents(ByVal src As String, ByVal dst As String) As Integer
' Leave function empty - DllImport attribute forces calls
End Function

调用时 RetVal = GetContents(sendurl.Text, sendtext.Text)
倒是可以调用,但无法 得到函数返回值...

...全文
133 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
速马 2005-06-22
  • 打赏
  • 举报
回复
OUT int &nTotalPacket应该对应ByRef intpage As Integer
还有这里为什么用CharSet:=CharSet.Unicode?既然原形是char*。
速马 2005-06-22
  • 打赏
  • 举报
回复
<DllImport("aa.DLL", EntryPoint:="GetContent", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> Public Shared Function GetContents(ByVal src As String, ByVal dst As String, ByVal contents As StringBuilder, ByRef intpage As Integer) As Integer
' Leave function empty - DllImport attribute forces calls
End Function
调用前,第三个参数,ByVal contents As StringBuilder,要先初始化,以开辟字符串缓冲区
qiri07 2005-06-22
  • 打赏
  • 举报
回复
本人无比倾佩 Sunmast(速马.上海) 兄弟!!!
对你的敬仰如 滔滔江水连绵不绝,犹如 黄河泛滥一发不可收拾
无条件奉送100分。

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧