I am new to using DLLs in Vb and am having a problem accessing a DLL function. I have a DLL with the following IDL file:
//************************
**********
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: prxySayHi.DLL
[ uuid(1D5A64A8-6705-4156-B4
B6-0354E3A
96A3F), version(1.0)]
library prxySayHi
{
// TLib : // TLib : OLE Automation : {00020430-0000-0000-C000-0
0000000004
6}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
dispinterface _intfcSayHi;
[
uuid(2D02AD08-4CB8-4857-8C
AB-85828BF
C8CFD),
helpstring("Generated on Tuesday, March 20, 2007 03:43:39 PM")
]
dispinterface _intfcSayHi {
properties:
methods:
[id(0x00000001)]
long methdSayHi(
[in, out,
custom({F0D491D0-0DF9-4ECA
-AFB0-5C57
3ABE9325},
"100")
] BSTR* vDataBuf,
[out,
custom({F0D491D0-0DF9-4ECA
-AFB0-5C57
3ABE9325},
"0")
] long* tpurcode);
};
[
uuid(2E2E8AFE-DEBD-4C51-95
2C-105C89C
98627),
appobject
]
coclass intfcSayHi {
[default] dispinterface _intfcSayHi;
};
};
//************************
**********
The purpose of the DLL is just to pass a "Hello" message back to the calling program.
I am using VB 2005 Express to write the calling program. I have creaded a button to execute the call and a text field to display the "Hello" response.
When I view the dll in the object browser, I see two options available: prxySayHi.intfcSayHi and prxySayHi._intfcSayHi both showing my methdSayHi with appropriate variables.
If i call it using prxySayHi.intfcSayHi I get the following error:
'Unable to cast COM object of type 'prxySayHi.intfcSayHiClass
' to interface type 'prxySayHi._intfcSayHi'. This operation failed because the QueryInterface call on the COM component for the interface with IID "
This is the code I'm using:
'**********************-St
art-******
**********
**********
*
Public Class GetHi
Private Sub cmdGetHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetHello.Click
Dim intRetVal As Integer
Dim strDataBuf As String
Dim intUrCode As Int32
Dim objCSayHi As prxySayHi.intfcSayHi
objCSayHi = New prxySayHi.intfcSayHi
strDataBuf = "Hi"
intRetVal = objCSayHi.methdSayHi(strDa
taBuf, intUrCode)
Me.txtHelloMsg.Text = strDataBuf
End Sub
End Class
'**********************-En
d-********
**********
*********
If I try to use the interface type 'prxySayHi._intfcSayHi' usning the following code I get other errors.
'**********************-St
art-******
**********
**********
*
Public Class GetHi
Private Sub cmdGetHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetHello.Click
Dim intRetVal As Integer
Dim strDataBuf As String
Dim intUrCode As Int32
Dim objISayHi As prxySayHi._intfcSayHi
objISayHi = New prxySayHi._intfcSayHi
strDataBuf = "Hi"
intRetVal = objISayHi.methdSayHi(strDa
taBuf, intUrCode)
Me.txtHelloMsg.Text = strDataBuf
End Sub
End Class
'**********************-En
d-********
**********
*********
With this code on the 'objISayHi = New prxySayHi._intfcSayHi" line I get an error : "'New' cannot be used on an interface. "
If I remove this line I get the following warning: "Variable 'objISayHi' is used before it has been assigned a value. A null reference exception could result at runtime."
If I ignore the warning and run the app I get - amazingly - a "NullReferenceException was unhandled" error.
I know I must be donig something stupid but I'm missing it. Any suggestions???
Thanks, Diane
Start Free Trial