Board index » cppbuilder » I am sure this is an easy question

I am sure this is an easy question

Hello,

I am trying to build a client that will pass
a string { char buffer[ 100 ] } to a server.

Please someone show me the way.  Here is what I am currently doing ...

My client code :

void __fastcall TForm1::Button1Click(TObject *Sender)
{
   char buffer[ 100 ];

   strcpy( buffer, "password" );
   TCOMIPowers P = CoPowers::Create();
   P -> LogOn( buffer );

Quote
}

My type library declaration :
        virtual HRESULT STDMETHODCALLTYPE
                LogOn(LPSTR Password/*[in]*/) = 0; // [1]

I get an exception everytime I try to run it -- something to
do with the way I am declaring types I suppose ...

Please Help ... thanks a lot !!!

 

Re:I am sure this is an easy question


Quote
mattk wrote in message <355B5802.4...@kmc-controls.com>...
>I am trying to build a client that will pass
>a string { char buffer[ 100 ] } to a server.

If this is an Automation server you can't use a char/LPSTR.  You are limited
to the types supported by Automation.  Instead of a LPSTR you need to use a
BSTR.

Instead of:

Quote
>My type library declaration :
> virtual HRESULT STDMETHODCALLTYPE
> LogOn(LPSTR Password/*[in]*/) = 0; // [1]

Try:
     virtual HRESULT STDMETHODCALLTYPE LogOn( BSTR Password/*[in]*/) = 0 ;

And Instead of:

Quote
>My client code :

>void __fastcall TForm1::Button1Click(TObject *Sender)
>{
>   char buffer[ 100 ];

>   strcpy( buffer, "password" );
>   TCOMIPowers P = CoPowers::Create();
>   P -> LogOn( buffer );
>}

Try:

     P->LogOn( WideString( buffer ).Detach() ) ;

A WideString is a class that wraps up BSTRs.  If you don't want to work with
a wrapper you'll need to manually allocate and free your BSTRs with
SysAllocString and SysFreeString.  For more info on BSTRs refer to the
WinAPI OLE helpfile.  For more info on WideString you can look at the
wstring.h header file in your Include folder.  Charlie Calvert also has a
document on his Tech Voyage web page that discusses wide strings:

http://www.inprise.com/bcppbuilder/books/chapter17/

Hope this helps.

Re:I am sure this is an easy question


Thanks for your response, but

LPSTR is one of the choices in the dropdown list box.  
If this is not a valid type for automation, why is it there ???

Just wondering ....

Quote
Jason Cone wrote:

> mattk wrote in message <355B5802.4...@kmc-controls.com>...
> >I am trying to build a client that will pass
> >a string { char buffer[ 100 ] } to a server.

> If this is an Automation server you can't use a char/LPSTR.  You are limited
> to the types supported by Automation.  Instead of a LPSTR you need to use a
> BSTR.

> Instead of:
> >My type library declaration :
> > virtual HRESULT STDMETHODCALLTYPE
> > LogOn(LPSTR Password/*[in]*/) = 0; // [1]

> Try:
>      virtual HRESULT STDMETHODCALLTYPE LogOn( BSTR Password/*[in]*/) = 0 ;

> And Instead of:
> >My client code :

> >void __fastcall TForm1::Button1Click(TObject *Sender)
> >{
> >   char buffer[ 100 ];

> >   strcpy( buffer, "password" );
> >   TCOMIPowers P = CoPowers::Create();
> >   P -> LogOn( buffer );
> >}

> Try:

>      P->LogOn( WideString( buffer ).Detach() ) ;

> A WideString is a class that wraps up BSTRs.  If you don't want to work with
> a wrapper you'll need to manually allocate and free your BSTRs with
> SysAllocString and SysFreeString.  For more info on BSTRs refer to the
> WinAPI OLE helpfile.  For more info on WideString you can look at the
> wstring.h header file in your Include folder.  Charlie Calvert also has a
> document on his Tech Voyage web page that discusses wide strings:

> http://www.inprise.com/bcppbuilder/books/chapter17/

> Hope this helps.

Other Threads