从VB.NET访问VC ++ MFC dll [英] Accessing a VC++ MFC dll from VB.NET

查看:57
本文介绍了从VB.NET访问VC ++ MFC dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我尝试从vb.net访问VC ++ MFC dll函数时,它显示"PInvoke限制:无法返回变体."

VC ++代码:

Hi,

While i am trying to access a VC++ MFC dll function from vb.net, it is showing "PInvoke restriction: cannot return variants."

VC++ code:

EXTERN_C void FAR PASCAL EXPORT CreateGUID(BSTR* bstrGUID,short ID)
{
	CString strGUID;
	AfxBSTR2CString(&strGUID, *bstrGUID);
	ACNCreateNewGUID(strGUID,ID);
	*bstrGUID = strGUID.GetBuffer() ;
	//return strGUID;
}		


访问功能CreateGUID的VB.NET代码:


VB.NET code to access teh function CreateGUID:

Public Class Form1
Public Declare Function CreateGUID Lib "GUIDDll.dll" (ByRef sStr As String, ByVal iNum As Short)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim exstr As String = ""        
        MessageBox.Show(CreateGUID(exstr, 10))
    End Sub
End Class


请帮助我解决此P/Invoke问题.

预先感谢,
Sivakumar.M.


Kindly help me please to sort out this P/Invoke issue.

Thanks in advance,
Sivakumar.M.

推荐答案

不确定VB,所以如果我错了,请抱歉,但是您的C函数不会返回值.

所以我想,您应该将其标记为不返回任何内容,应该单独调用它,然后在MessageBox中使用exstr变量.
Not sure abour VB, so sory if I''m wrong, but your C function doesn''t return a value.

So I suppose, you should have it marked as returning nothing, you should call it separatelly and thereafter use the exstr variable in MessageBox.


这篇关于从VB.NET访问VC ++ MFC dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆