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
Re: Getting variable from dll function
Quote:
Originally Posted by
btpoole
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
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.
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.
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.
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.
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?
Re: Getting variable from dll function
Function get_ChannelNumber() As <Unsupported variant type>
Member of HAUPPAUGETVSERVERLib.IHCWTuneRequest
This is from object browser
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.
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.
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.
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
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
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.
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.
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
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
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
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.
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
Re: Getting variable from dll function
I guess my confusion is that the retval is used for multiple items as shown.
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