Results 1 to 21 of 21

Thread: Getting variable from dll function

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Getting variable from dll function

    Have a vb6 app that used functions from a dll written in c++. I have referenced the dll and have used dependecy to view the entry points of the dll. I have a declare function setup as follows:
    Declare Function DllGetClassObject Lib "myfile.dll" (ByRef object1 as long, object2 as long, object3 as long) As Long
    According to the dependency viewer there are five functions. The DllGetClassObject is one of them. The function has numerous objects. I am only interested in calling three of them. There are probably 10 total. If I use the code as shown I get argument is not optional error. Does this mean I have to enter all objects in the declare statement? If so is there anyway to pass them to the function as an array. If it does not mean this, what would be missing to produce this error?
    Thanks for any advice

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Getting variable from dll function

    Quote Originally Posted by btpoole View Post
    If I use the code as shown I get argument is not optional error. Does this mean I have to enter all objects in the declare statement?
    Yes, you have to pass all required arguments. But if you want, in your Declare statement, you may use the Optional keyword if a parameter (and subsequent parameters) can accept 0& (or NULL).

    Quote Originally Posted by btpoole View Post
    If so is there anyway to pass them to the function as an array. If it does not mean this, what would be missing to produce this error?
    That won't work. You really need to supply all the parameters needed by that function. Can you post that function's prototype? Some documentation of that function would be helpful too.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    Thanks Bonnie. The actual dll controls a tuner card. When viewed in dll viewer there are five exported functions.
    1. DLLCANUNLOADNOW
    2. DLLGETCLASSOBJECT
    3. DLLREGISTERSERVER
    4. DLLUNREGISTERSERVER
    5. GETPROXDLLINFO

    When I view dll with ole under Interfaces, I can see the multitude of classes along with the methods associated with the objects. Shown below is the class IHCWTuneRequest methods.
    odl,
    uuid(B1AF2E2F-77F5-44BF-9CDC-9327E7058381)
    ]
    interface IHCWTuneRequest : IUnknown {
    HRESULT _stdcall get_CountryCode([out, retval] unsigned long* retval);
    HRESULT _stdcall put_CountryCode([in] unsigned long countryCode);
    HRESULT _stdcall get_ChannelNumber([out, retval] unsigned long* retval);
    HRESULT _stdcall put_ChannelNumber([in] unsigned long chNumber);
    HRESULT _stdcall get_FineTune([out, retval] unsigned long* retval);
    HRESULT _stdcall put_FineTune([in] unsigned long fineTune);
    HRESULT _stdcall get_TuneFormat([out, retval] unsigned long* retval);
    HRESULT _stdcall put_TuneFormat([in] unsigned long chNumber);
    HRESULT _stdcall get_VideoFormat([out, retval] unsigned long* retval);
    HRESULT _stdcall put_VideoFormat([in] unsigned long chNumber);
    HRESULT _stdcall get_BroadcastSource([out, retval] unsigned long* retval);
    HRESULT _stdcall put_BroadcastSource([in] unsigned long chNumber);
    HRESULT _stdcall get_TuningSpace([out, retval] ITuningSpace** retval);
    HRESULT _stdcall get_Components([out, retval] IComponents** retval);
    HRESULT _stdcall get_Locator([out, retval] ILocator** retval);
    HRESULT _stdcall put_Locator([in] ILocator* Locator);
    HRESULT _stdcall get_Source([out, retval] IHCWSource** retval);
    HRESULT _stdcall get_DoIRBlaster([out, retval] long* pVal);
    HRESULT _stdcall put_DoIRBlaster([in] long pVal);
    HRESULT _stdcall get_IRBlasterChanNum([out, retval] long* pVal);
    HRESULT _stdcall put_IRBlasterChanNum([in] long pVal);
    HRESULT _stdcall get_RollOff([out, retval] unsigned long* pVal);
    HRESULT _stdcall put_RollOff([in] unsigned long pVal);
    HRESULT _stdcall get_Pilot([out, retval] unsigned long* pVal);
    HRESULT _stdcall put_Pilot([in] unsigned long pVal);
    HRESULT _stdcall get_S2Modulation([out, retval] unsigned long* pVal);
    HRESULT _stdcall put_S2Modulation([in] unsigned long pVal);
    HRESULT _stdcall get_AudioInput([out, retval] unsigned long* retval);
    HRESULT _stdcall put_AudioInput([in] unsigned long audioInput);

    I am trying to retrieve the current channel number that maybe active at a given time. I assume this would be done from get_ChannelNumber method. Any additional help on this would be appreciated.

  4. #4
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Getting variable from dll function

    Looks like you have an ActiveX DLL. You said you've referenced the DLL. Doesn't its Type Library show up in the IDE's Object Browser? You should be able to use the functions listed there instead of declaring them yourself with the Declare statement.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    You are correct Bonnie, for some reason I overlooked this. I think I have read too many post about doing this and was trying to combine things. I am able to to use the functions listed. Now I get a compile error, Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic. Not sure what this one is, never got this far with app.

  6. #6
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Getting variable from dll function

    Which function are you getting that error? Can you please right-click on it and select Definition? And then can you please copy that function's description at the bottom and paste it here?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    Function get_ChannelNumber() As <Unsupported variant type>
    Member of HAUPPAUGETVSERVERLib.IHCWTuneRequest
    This is from object browser

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Getting variable from dll function

    I think you won't be able to use that function with VB6. From your earlier post, it seems get_ChannelNumber returns an unsigned long type. VB6 doesn't have unsigned Integers except for Byte, so VB6 doesn't recognize that function's return value. If you have the source code for the DLL, you may be able to convert it to a more suitable data type.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    Thanks Bonnie. After reading some more I think you are correct. I was hoping to find something to convert to something suitable. Thanks for your help.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    I have another dll that basically has all the same functions as the original one above, there is a difference in that the methods return the get_ChannelNo as long. I have referenced that dll and able to select the desired methods but now I get a type mismatch error. I have the following
    dim curchannel as IHCWService
    Set curchannel=curchannel.get_ChannelNo

    When code executes, I get the type mismatch. The object browser has it listed as long.

  11. #11
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Getting variable from dll function

    I think it should be:

    Code:
    Dim curchannel As IHCWService
    Set curchannel = New IHCWService
    Debug.Print curchannel.get_ChannelNo
    Last edited by Bonnie West; May 12th, 2013 at 11:29 PM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Getting variable from dll function

    you only use SET when SETting an object... the .get_ChannelNo is a property that returns a long... not an object... so there's no need to SET the variable...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    In the code

    Dim curchannel As IHCWService
    Set curchannel = New IHCWService
    Debug.Print curchannel.get_ChannelNo

    I get the error Invalid use of keyword New when set curchannel. If I remove New as shown

    Dim curchannel As IHCWService
    Set curchannel = IHCWService
    Debug.Print curchannel.Get_ChannelNo

    I get object required.

    If I use the set statement
    Set curchannel=curchannel.Get_ChannelNo
    I get type mismatch.
    I did not think it was going to be this difficult to get a value returned from the dll. According to object browser IHCWService is the class and get_ChannelNo is the function returning a long.

  14. #14
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Getting variable from dll function

    IHCWService probably cannot be instantiated directly. Browse the available classes and their functions in that DLL's Type Library and see which one(s) return the IHCWService class. That is, the IHCWService class is quite likely a return value of some function(s) in that library which you have to call first. It would help immensely if that DLL came with some documentation that explains how to use it.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    Looks like it maybe a class in one dll but is created from another dll, which luckily I have. Trying to sort thru it all. Thanks again

  16. #16

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    How can an unknown variable be passed to vb from dll. Example:
    HRESULT _stdcall get_ServiceID([out, retval] long* retval);
    How is vb6 coded to call the return value as long when no variable name is given?
    Thanks

  17. #17
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Getting variable from dll function

    Huh? What do you mean no variable name is given? retval is the variable name... from the DLL side... from the VB side, you pass it any Long variable you want... Oh... wait... that's a C long isn't it? Hmmmm....

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  18. #18

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    Yes c. Here is more of the dll
    [
    odl,
    uuid(0AB436C8-E499-4700-A716-806C77D5A2E0)
    ]
    interface IHCWService : IUnknown {
    HRESULT _stdcall get_ServiceID([out, retval] long* retval);
    HRESULT _stdcall put_ServiceID([in] long val);
    HRESULT _stdcall get_PreferredDataPid([out, retval] int* retval);
    HRESULT _stdcall get_SourceFriendlyName([out, retval] BSTR* retval);

    I assume the retval is define as code runs.

  19. #19
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Getting variable from dll function

    it's defined right there... it's the name of the parameter... it's just like any other method you would create in VB... I'm not sure what the disconnect is, except that you may have issues with the long* as it's a C-long... for which VB6 doesn't have an equivalent for... as it would need to be a double long... but that doesn't exist...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Nov 2012
    Posts
    21

    Re: Getting variable from dll function

    I guess my confusion is that the retval is used for multiple items as shown.

  21. #21
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Getting variable from dll function

    yes... you can use the same parameter name across multiple methods... one has nothing to do with the other... it's just a name.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width