Advertisement

03.22.2007 at 08:31AM PDT, ID: 22465902
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2

Using a DLL in VB

Asked by diane903 in Windows OLE Programming, Visual Basic Programming, Microsoft Visual Studio Express

Tags: , ,

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-B4B6-0354E3A96A3F),  version(1.0)]
library prxySayHi
{
    // TLib :     // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");
    // Forward declare all types defined in this typelib
    dispinterface _intfcSayHi;
    [
      uuid(2D02AD08-4CB8-4857-8CAB-85828BFC8CFD),
      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-5C573ABE9325}, "100")            
           
] BSTR* vDataBuf,
                            [out,
                custom({F0D491D0-0DF9-4ECA-AFB0-5C573ABE9325}, "0")            
           
] long* tpurcode);
    };
    [
      uuid(2E2E8AFE-DEBD-4C51-952C-105C89C98627),
      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:
'**********************-Start-***************************
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(strDataBuf, intUrCode)
        Me.txtHelloMsg.Text = strDataBuf
    End Sub
End Class
'**********************-End-***************************

If I try to use the interface type 'prxySayHi._intfcSayHi' usning the following code I get other errors.

'**********************-Start-***************************
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(strDataBuf, intUrCode)
        Me.txtHelloMsg.Text = strDataBuf
    End Sub
End Class
'**********************-End-***************************
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
[+][-]03.22.2007 at 09:19AM PDT, ID: 18772491

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.22.2007 at 09:22AM PDT, ID: 18772522

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.22.2007 at 09:36AM PDT, ID: 18772644

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.22.2007 at 09:36AM PDT, ID: 18772647

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.22.2007 at 09:42AM PDT, ID: 18772705

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.26.2007 at 12:46PM PDT, ID: 18795450

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.08.2007 at 12:42PM PDT, ID: 19657336

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.13.2007 at 02:37AM PDT, ID: 19882491

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.14.2007 at 07:51AM PDT, ID: 19892041

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.05.2008 at 04:25PM PST, ID: 20591851

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]01.10.2008 at 07:06PM PST, ID: 20633787

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Windows OLE Programming, Visual Basic Programming, Microsoft Visual Studio Express
Tags: dll, vb, using
Sign Up Now!
Solution Provided By: Computer101
Participating Experts: 4
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44