Click here to Skip to main content
15,878,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C++
EXTERN_C void FAR PASCAL EXPORT CreateGUID(BSTR* bstrGUID,short ID)
{
	CString strGUID;
	AfxBSTR2CString(&strGUID, *bstrGUID);
	ACNCreateNewGUID(strGUID,ID);
	*bstrGUID = strGUID.GetBuffer() ;
	//return strGUID;
}		

VB.NET code to access teh function CreateGUID:
VB
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

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

Thanks in advance,
Sivakumar.M.
Posted
Updated 15-Sep-10 7:35am
v2

1 solution

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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900