BSTR*
-
I got to use an activeX control in my VC++ project. When I import the control its wrapper class had a function as below, void CVTSID::Connect(BSTR* RemHost, long* RemPort) { static BYTE parms[] = VTS_PBSTR VTS_PI4; InvokeHelper(0x60030012, DISPATCH_METHOD, VT_EMPTY, NULL, parms, RemHost, RemPort); } I tried to pass the parameters as below, CString str = "192.168.1.155"; BSTR host = str.AllocSysString(); long port = 3246; m_dvt.Connect(&host,&port); The function fails! How I should pass the parameter:confused:
-
I got to use an activeX control in my VC++ project. When I import the control its wrapper class had a function as below, void CVTSID::Connect(BSTR* RemHost, long* RemPort) { static BYTE parms[] = VTS_PBSTR VTS_PI4; InvokeHelper(0x60030012, DISPATCH_METHOD, VT_EMPTY, NULL, parms, RemHost, RemPort); } I tried to pass the parameters as below, CString str = "192.168.1.155"; BSTR host = str.AllocSysString(); long port = 3246; m_dvt.Connect(&host,&port); The function fails! How I should pass the parameter:confused:
_CString str = "192.168.1.155"; BSTR host = str.AllocSysString(); long port = 3246; m_dvt.Connect(&host,&port);_
First, you are going a really long way just to create aBSTR
, you can save yourself one allocation:CComBSTR bstrHost( "192.168.1.155" ); long port = 3246; m_dvt.Connect(&bstrHost,&port);
Second, what error is being returned? It looks like you are calling the method correctly, was the object created correctly? Third, when you have to pass pointers to a COM method, it is often because you are going to get something back from the method via those pointers. COM rules state that if you pass aBSTR
pointer, you own whateverBSTR
comes back via that pointer, and you transfer ownership of theBSTR
you sent, if any.CComBSTR
will automatically deallocate theBSTR
(either the one it created, or the one you get back) when its destructor fires. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!) -
_CString str = "192.168.1.155"; BSTR host = str.AllocSysString(); long port = 3246; m_dvt.Connect(&host,&port);_
First, you are going a really long way just to create aBSTR
, you can save yourself one allocation:CComBSTR bstrHost( "192.168.1.155" ); long port = 3246; m_dvt.Connect(&bstrHost,&port);
Second, what error is being returned? It looks like you are calling the method correctly, was the object created correctly? Third, when you have to pass pointers to a COM method, it is often because you are going to get something back from the method via those pointers. COM rules state that if you pass aBSTR
pointer, you own whateverBSTR
comes back via that pointer, and you transfer ownership of theBSTR
you sent, if any.CComBSTR
will automatically deallocate theBSTR
(either the one it created, or the one you get back) when its destructor fires. Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)I receive two errors, 1."Run-time error'9': Subscript out of range" from activeX control itself. 2."Application-defined or object-defined error" thrown by the application.
-
I receive two errors, 1."Run-time error'9': Subscript out of range" from activeX control itself. 2."Application-defined or object-defined error" thrown by the application.
I came to know the problem is within the activeX control itself. I download the latest control and its working fine without errors. Thank you James.