Stupid question about Automation
-
Hello guys, I'm novice in VB 6.0 but have some skill in VC++. I'm developing COM-server using Visual C++ and "thin client" in VB 6.0 ("late binding"). One of function is present in COM-server as follows: [id(5), helpstring("method Encoder")] HRESULT Encoder([out] long * Result, [out] long * LastError); As you see, method "Encoder" receives two pointers to long data type. I can invoke that method from client written on Visual C++, but I can't do that on VB. Is it possible to call method "Encoder" from VB Client? How? Or I need to rewrite my COM-server and include two separate methods: - get_EncoderResult - get_EncoderLastError ? Yours sincerely, Alex Bash
-
Hello guys, I'm novice in VB 6.0 but have some skill in VC++. I'm developing COM-server using Visual C++ and "thin client" in VB 6.0 ("late binding"). One of function is present in COM-server as follows: [id(5), helpstring("method Encoder")] HRESULT Encoder([out] long * Result, [out] long * LastError); As you see, method "Encoder" receives two pointers to long data type. I can invoke that method from client written on Visual C++, but I can't do that on VB. Is it possible to call method "Encoder" from VB Client? How? Or I need to rewrite my COM-server and include two separate methods: - get_EncoderResult - get_EncoderLastError ? Yours sincerely, Alex Bash
Both VBScript and VB can't call via IDispatch (what you call "late binding" in VB world) methods that receive arguments ByRef. You can do this via early binding, though. I see you have your IDL interface defined, so why are you calling this using late binding? Trying to make bits uncopyable is like trying to make water not wet. -- Bruce Schneier By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn
-
Hello guys, I'm novice in VB 6.0 but have some skill in VC++. I'm developing COM-server using Visual C++ and "thin client" in VB 6.0 ("late binding"). One of function is present in COM-server as follows: [id(5), helpstring("method Encoder")] HRESULT Encoder([out] long * Result, [out] long * LastError); As you see, method "Encoder" receives two pointers to long data type. I can invoke that method from client written on Visual C++, but I can't do that on VB. Is it possible to call method "Encoder" from VB Client? How? Or I need to rewrite my COM-server and include two separate methods: - get_EncoderResult - get_EncoderLastError ? Yours sincerely, Alex Bash
That's because VC++ can handle [out] parameters - VB cannot. In order to return a logical value back to a VB client your interface's final parameter must be marked as [out, retval]. However, you're wanting to return multiple values which is best suited for SAFEARRAYS. So your question was: Is it possible to call method "Encoder" from VB Client? How? With your current implementation? No
-
Both VBScript and VB can't call via IDispatch (what you call "late binding" in VB world) methods that receive arguments ByRef. You can do this via early binding, though. I see you have your IDL interface defined, so why are you calling this using late binding? Trying to make bits uncopyable is like trying to make water not wet. -- Bruce Schneier By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn
Really? ' Client's code - VB6:
Dim o As Cx, o2 As Object
Dim p1 As Long, p2 As Long
...
Set o = New Cx
Set o2 = o
...
p1 = 0: p2 = 0
o.Encoder p1, p2 ' Call by vtable => early binding
p1 = 0: p2 = 0
o2.Encoder p1, p2 ' Call by GetIdsOfName&Invoke => late binding
p1 = 0: p2 = 0
CallByName o, "Encoder", VbMethod, p1, p2 ' forcible late binding
p1 = 0: p2 = 0
CallByName o2, "Encoder", VbMethod, p1, p2' Server's code - C++:
STDMETHODIMP Cx::Encoder(/*[out]*/ long * Result, /*[out]*/ long * LastError)
{
*Result = 22;
*LastError = 222;
return S_OK;
}With best wishes, Vita
-
Really? ' Client's code - VB6:
Dim o As Cx, o2 As Object
Dim p1 As Long, p2 As Long
...
Set o = New Cx
Set o2 = o
...
p1 = 0: p2 = 0
o.Encoder p1, p2 ' Call by vtable => early binding
p1 = 0: p2 = 0
o2.Encoder p1, p2 ' Call by GetIdsOfName&Invoke => late binding
p1 = 0: p2 = 0
CallByName o, "Encoder", VbMethod, p1, p2 ' forcible late binding
p1 = 0: p2 = 0
CallByName o2, "Encoder", VbMethod, p1, p2' Server's code - C++:
STDMETHODIMP Cx::Encoder(/*[out]*/ long * Result, /*[out]*/ long * LastError)
{
*Result = 22;
*LastError = 222;
return S_OK;
}With best wishes, Vita
Vi2 wrote: Really? ' Client's code - VB6:
Dim o As Cx, o2 As Object Dim p1 As Long, p2 As Long ... Set o = New Cx Set o2 = o ... p1 = 0: p2 = 0 o.Encoder p1, p2 ' Call by vtable => early binding
Vi2 wrote:
STDMETHODIMP Cx::Encoder(/*[out]*/ long * Result, /*[out]*/ long * LastError) { *Result = 22; *LastError = 222; return S_OK; }
I don't think a call to Encoder from a VB6 client will work with the above Encoder definition. At least when I attempted to call Encoder from a VB client using the above Encoder definition in a C++ COM object the program crashed. Is this normal behavior? Or, am I overlooking something? Thanks,