BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Setting Up a New ActiveX Link

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX)
View previous topic :: View next topic  
Author Message
LarryJ
Guest





PostPosted: Sat Mar 03, 2007 9:10 am    Post subject: Setting Up a New ActiveX Link Reply with quote



I am using BCB6.0 and I am trying to setup a new ActiveX link to a third
party application. The only advice to create the object from the third party
developers is a Microsoft method and I am not sure how to convert this into
Borland code. I have been trying to use the CreateInstance(...) but I can
not create the correct object. The wrapper component created and imported
by C++Builder does create the correct object but I am not able to handle the
exceptions that hit the OLECHECK and then require my app be restarted to
reset the ActiveX link. I was hoping to create the object with code and
then figure out a better way to handle the exceptions. Do you see how I
might create the correct object? I can email the complete type libraries if
needed.


===========================
I believe your syntax should be Activator.CreateInstance. See this link for
more info.

http://msdn2.microsoft.com/en-us/library/system.activator.createinstance(VS.80).aspx

You should use the standard method (eg. esignal = new
IESignal.HooksClass(); )

=============================
// *********************************************************************//
// GUIDS declared in the TypeLibrary
// *********************************************************************//
const GUID LIBID_IESignal = {0x9C7CCB46, 0xE9E8, 0x4DDD,{ 0x97, 0x84,
0x44,0x58, 0x87, 0x7C,0x2F, 0x10} };
const GUID GUID_BarData = {0x847437AD, 0xC3AC, 0x4D09,{ 0xB4, 0x1D,
0x17,0x6B, 0xED, 0x48,0x84, 0x43} };
const GUID GUID_BasicQuote = {0x63F7D66E, 0x0705, 0x4F36,{ 0x9C, 0xA6,
0x17,0x1E, 0xB5, 0x01,0xE5, 0xA5} };
const GUID GUID_OrderItem = {0x006C45AD, 0x7624, 0x4131,{ 0xBB, 0xE6,
0x69,0xEE, 0x44, 0xD8,0x92, 0xF2} };
const GUID GUID_TimeSalesFilter = {0x01ADEF9C, 0x5252, 0x43B4,{ 0x90, 0xBC,
0xA5,0x2E, 0x2C, 0x7A,0xA7, 0x03} };
const GUID GUID_TimeSalesData = {0x30A6CBE2, 0x5B08, 0x4185,{ 0xB7, 0xB3,
0xDA,0x43, 0x66, 0xDF,0x77, 0x38} };
const GUID IID_IHooks = {0xC5916B45, 0xA7EB, 0x4919,{ 0xA7, 0x42, 0xAD,0x47,
0xAE, 0x3A,0xE9, 0x96} };
const GUID IID_IBrokerGUI = {0x667ADD3B, 0xAB3D, 0x4C5A,{ 0x80, 0xEC,
0x13,0x3E, 0xD6, 0x44,0xD2, 0xE1} };
const GUID DIID__IHooksEvents = {0x3EBD5210, 0xC4E9, 0x4602,{ 0x92, 0x68,
0x20,0xF0, 0xCB, 0x7B,0x25, 0x84} };
const GUID DIID__IBrokerGUIEvents = {0x2936DA6E, 0x7AF8, 0x49C1,{ 0x90,
0xC3, 0x73,0xBD, 0xF1, 0xEF,0x77, 0xFE} };
const GUID CLSID_Hooks = {0x4A0DD8DE, 0x25D5, 0x419D,{ 0xA8, 0xE7,
0x36,0x15, 0xB9, 0x8A,0xDB, 0x0B} };


Thanks for looking
Larry Johnson
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Mar 03, 2007 9:10 am    Post subject: Re: Setting Up a New ActiveX Link Reply with quote



"LarryJ" <LarryJ33 (AT) austin (DOT) rr.com> wrote in message
news:45e9208d$1 (AT) newsgroups (DOT) borland.com...

Quote:
I am using BCB6.0 and I am trying to setup a new ActiveX link to
a third party application. The only advice to create the object from
the third party developers is a Microsoft method and I am not sure
how to convert this into Borland code.

There is nothing to convert. ActiveX is standardized. Code that
works in VC++ can work in Borland as well.

Quote:
I have been trying to use the CreateInstance(...) but I can not
create
the correct object.

There is only one object available in the IIDs that you have shown, so
it is hard not to create the correct object.

Quote:
The wrapper component created and imported by C++Builder
does create the correct object

Importing the control only automates the process that the code you
have shown is doing manually, but the outcome is the same.

Quote:
I am not able to handle the exceptions that hit the OLECHECK and
then require my app be restarted to reset the ActiveX link.

What exceptions are you referring to? Please be more specific.

Quote:
Do you see how I might create the correct object?

You did not show the code you are using to create the object. It
should be something like this:

IHooks *pHooks = NULL;
CoCreateInstance(CLSID_Hooks, NULL, CLSCTX_INPROC_SERVER,
IID_IHooks, (LPVOID*)&pHooks);
if( pHooks )
{
// use pHooks as needed...
pHooks->Release();
}


Quote:
I believe your syntax should be Activator.CreateInstance. See
this link for more info.

That is for .NET code only. That has nothing to do with this.


Gambit
Back to top
LarryJ
Guest





PostPosted: Sun Mar 04, 2007 12:23 am    Post subject: Re: Setting Up a New ActiveX Link Reply with quote



I originally tried to create the object using TCOMIHooks as below but I get
the error "is not a member of IHooks" for functions like "Connect"
"Disconnect" "GetBasicQuote" and "RequestHistory" that I have access to when
I use the Borland wrapper component.

TCOMIHooks TC;
HRESULT hr = TC.CreateInstance( CLSID_Hooks );


When I create the object using the code you posted the same error occurs "is
not a member of IHooks". for example the functions below named "Connect"
"Disconnect" "GetBasicQuote" and "RequestHistory". So the Borland Wrapper
seems to be creating a different object which allows access to all the
AxtiveX functions. Maybe the wrapper is creating more than one object?

//from the IESignal_OCX.h file
class PACKAGE THooks : public Oleserver::TOleServer
{
IHooksPtr m_DefaultIntf;
_di_IUnknown __fastcall GetDunk();
public:
__fastcall THooks(TComponent* owner) : Oleserver::TOleServer(owner)
{}

IHooksPtr& GetDefaultInterface();
void __fastcall InitServerData();
void __fastcall Connect();
void __fastcall Disconnect();
void __fastcall BeforeDestruction();
void __fastcall ConnectTo(IHooksPtr intf);

virtual void __fastcall InvokeEvent(int DispID, Oleserver::TVariantArray&
params);


Iesignal_tlb::BasicQuote __fastcall get_GetBasicQuote(BSTR sSymbol)
{
return GetDefaultInterface()->get_GetBasicQuote(sSymbol);
}

long __fastcall get_RequestHistory(BSTR sSymbol, BSTR sInterval,
Iesignal_tlb::barType btType,
long lNumBars, long lStartTime, long
lEndTime)
{
return GetDefaultInterface()->get_RequestHistory(sSymbol, sInterval,
btType, lNumBars,
lStartTime, lEndTime);
}

long __fastcall get_GetNumBars(long lHandle)
{
return GetDefaultInterface()->get_GetNumBars(lHandle);
}


\/\/\/\/\/ BREAK \/\/\/\/\/\/\/

This ActiveX object is processing data from a real-time stock data server
and a large amount of data is being passed from the server app to my client
app. A function like GetNumBars(long lHandle) seen above will sometime throw
an exception when the data load is heavy. The exception reaches the OLECHECK
and my app must be restarted to continue using the ActiveX functions without
any other problems. I am not able to handle the exceptions so my app will
continue working without showing the error message and require a restart.


Larry Johnson

"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message news:45e92f81
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sun Mar 04, 2007 3:13 am    Post subject: Re: Setting Up a New ActiveX Link Reply with quote

"LarryJ" <LarryJ33 (AT) austin (DOT) rr.com> wrote in message
news:45e9bd2c$1 (AT) newsgroups (DOT) borland.com...

Quote:
I originally tried to create the object using TCOMIHooks as below

That would work fine. TComInterface is just a wrapper class to manage
the reference counting of the interface, but provides direct access to
the interface otherwise.

Quote:
I get the error "is not a member of IHooks" for functions like
"Connect"
"Disconnect" "GetBasicQuote" and "RequestHistory" that I have access
to when I use the Borland wrapper component.

When I create the object using the code you posted the same error
occurs "is not a member of IHooks".

That is because you are not calling the interface's actual methods.
You are trying to call Borland's wrapper methods, which are different
and do not exist in the actual interface.

Quote:
for example the functions below named "Connect" "Disconnect"
"GetBasicQuote" and "RequestHistory".

Connect() and Disconnect() are Borland methods in the TOleServer class
only. They don't apply to the actual interface.

If you look at the code more closely, you will see that
GetBasicQuote() and RequestHistory() are actually named
get_GetBasicQuote() and get_RequestHistory() instead. That is how
they are named in the actual interface, and how they are named in
Borland's wrapper.

Quote:
So the Borland Wrapper seems to be creating a different object

No, it is not.

Quote:
Maybe the wrapper is creating more than one object?

No, it is not.

Quote:
This ActiveX object is processing data from a real-time stock data
server and a large amount of data is being passed from the server
app
to my client app. A function like GetNumBars(long lHandle) seen
above will sometime throw an exception when the data load is heavy.

Then you are likely using it wrong.

Quote:
The exception reaches the OLECHECK and my app must be restarted
to continue using the ActiveX functions without any other problems.

What is the actual HRESULT that is being returned by the interface
that is causing OLECHECK to throw an exceptions? What is the actual
exception being thrown, and what does it say? Are you wrapping any of
your code in try..catch blocks?

Quote:
I am not able to handle the exceptions

Yes, you can.


Gambit
Back to top
LarryJ
Guest





PostPosted: Mon Mar 05, 2007 2:39 am    Post subject: Re: Setting Up a New ActiveX Link Reply with quote

I didn't realize the Borland wrapper changed the actual interface names,
knowing that should solve most of the issues I had. Thanks a lot.


My experience with calling ActiveX functions is that the normal try catch
code will not prevent the error popup message created by the failure in the
OLECHECK. The only error I can create on demand is to call a function before
creating the ActiveX object so I will use that as an example. If I call the
ActiveX function IsEntitled before I create the ActiveX object an error
message with the text listed below pops up even though the function is
called inside the try catch. A similar error message occurs when the
interface is running and an expection occurs. I would like to prevent this
popup message and instead show a my own error message more appropriate for
the end user. In the code below the ShowMessage("IsEntitled failed"); will
never appear. How would I use try catch to capture this exception so I can
show my own error message?


void __fastcall TForm1::Button3Click(TObject *Sender)
{
bool Test=false;

try { Test = TC->IsEntitled;
}
catch(Exception&){ ShowMessage("IsEntitled failed");
}

}

//The Error Message I Can Not Catch Reads:
========================================
_ASSERTE:
intf !=0 @ c:\program files\borland\cbuilder6\include\vcl\utilcls.h/2916
Press [Y]es to terminate, [N]o to continue and [C]ancel to Debug
========================================


"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote in message
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Mar 05, 2007 4:26 am    Post subject: Re: Setting Up a New ActiveX Link Reply with quote

"LarryJ" <LarryJ33 (AT) austin (DOT) rr.com> wrote in message
news:45eb2eac$1 (AT) newsgroups (DOT) borland.com...

Quote:
I didn't realize the Borland wrapper changed the actual interface
names


It doesn't. You weren't using the original names to begin with.

Quote:
My experience with calling ActiveX functions is that the normal try
catch code will not prevent the error popup message created by
the failure in the OLECHECK.

What you are likely seeing is a call to MessageBox() before the
exception is thrown. To turn that off, you can go into the Project
Options and add NO_PROMPT_ON_HRCHECK_FAILURE to the Conditionals list.
The exception will then be thrown without any prompting, and your
try..catch will handle it normally without interruption.

Quote:
The only error I can create on demand is to call a function
before creating the ActiveX object so I will use that as an example.

Obviously, you can't call a method on an object that does not exist
yet. That is a very different kind of error.

Quote:
If I call the ActiveX function IsEntitled before I create the
ActiveX
object an error message with the text listed below pops up even
though the function is called inside the try catch.

If you are still using the TComInterface wrapper, the '->' operator
validates whether the interface pointer is available or not. If it is
not, an ASSERT is thrown. To disable the prompt on that error, you
can define NO_PROMPT_ON_ASSERTE_FAILURE in the Project Options.

Quote:
A similar error message occurs when the interface is running and
an expection occurs.

That is a different kind of error.

Quote:
In the code below the ShowMessage("IsEntitled failed"); will never
appear.


Yes, it will. But you have to click "Yes" on the error prompt first,
or else the exception is not thrown. Unless you disable the error
prompt altogether, then the exceptions is always thrown.

Quote:
How would I use try catch to capture this exception so I can show
my own error message?

You already are.

Quote:
catch(Exception&){

You should always catch exceptions by 'const' reference, ie:

catch(const Exception &){


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (ActiveX) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.