473,471 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using COM EXE in C#

My problem is that it keeps returing nothing after calling the
methods. I "TlbImp.exe TEST.exe /out:TESTCS.dll" and then in C# Right
click Add Reference Browse and give it the TESTCS.dll.

It adds "TESTCS" and I can use intellasence to see all the methods. I
do

TESTCS.Flower myFlower = new TESTCS.Flower();
MessageBox.Show(myFlower.get_GetFlower(2));

The "myFlower.GetFlower(2)" COM is suppose to return the 2nd flower
(stored in registry), which is a string. When I do this it says to
call accessor method directly "myFlower.get_GetFlower(2);" and this
just returns null.

I can use the COM EXE from my ASP/JScript pages using "object myFlower
= Server.CreateObject("TEST.myFlower);" and "myFlower.GetFlower(2);".
Just doesn't want to work in a Windows Form C# App.

Any suggestions? I've tried late binding, it seems more complicated
and I don't need late binding but it doesn't work either. Late
Binding code below:

Type objClassType;
objClassType = Type.GetTypeFromProgID("TEST.myFlower");
object objApp_Late = Activator.CreateInstance(objClassType);
objApp_Late.GetType().InvokeMember("GetFlower",
BindingFlags.InvokeMethod, null, objApp_Late, new object[] {55555});

It crashes at runtime with a "TargetInvocationException: Exception has
been thrown by the target of an Invocation." on the last line.

Thanks NB

Dec 18 '07 #1
3 3197
On Dec 18, 12:43 pm, NvrBst <nvr...@gmail.comwrote:
My problem is that it keeps returing nothing after calling the
methods. I "TlbImp.exe TEST.exe /out:TESTCS.dll" and then in C# Right
click Add Reference Browse and give it the TESTCS.dll.

It adds "TESTCS" and I can use intellasence to see all the methods. I
do

TESTCS.Flower myFlower = new TESTCS.Flower();
MessageBox.Show(myFlower.get_GetFlower(2));

The "myFlower.GetFlower(2)" COM is suppose to return the 2nd flower
(stored in registry), which is a string. When I do this it says to
call accessor method directly "myFlower.get_GetFlower(2);" and this
just returns null.

I can use the COM EXE from my ASP/JScript pages using "object myFlower
= Server.CreateObject("TEST.myFlower);" and "myFlower.GetFlower(2);".
Just doesn't want to work in a Windows Form C# App.

Any suggestions? I've tried late binding, it seems more complicated
and I don't need late binding but it doesn't work either. Late
Binding code below:

Type objClassType;
objClassType = Type.GetTypeFromProgID("TEST.myFlower");
object objApp_Late = Activator.CreateInstance(objClassType);
objApp_Late.GetType().InvokeMember("GetFlower",
BindingFlags.InvokeMethod, null, objApp_Late, new object[] {55555});

It crashes at runtime with a "TargetInvocationException: Exception has
been thrown by the target of an Invocation." on the last line.

Thanks NB
Update: Reasion its not working in the C# Application is because the
"CmyFlower::OnPageStart(IUnknown* piUnk) {...}" isn't being called
automatically. I created an ASP.NET/C# page and in the default
codebehind file I make a function

public string GetFlower(){TEST.Flower myFlower = new TEST.Flower();
return myFlower.get_GetFlower(2);}

And in my form I do "<% Response.Write(GetFlower()); %>" But I still
only get null because a varible in the COMs "OnPageStart(IUnknown*
piUnk)" method isn't getting set. Does "new TEST.Flower();" not call
that function automatically like "Server.CreateObject("TEST.Flower");"
does?

I don't mind calling the "OnPageStart(IUnknown)" manually but I'm
unable to find what they want as the arg ("piUnk"). My ASP.NET Code
behind file extends System.Web.Page so I think I should have the
"piUnk" they want someplace... I tried giving it a random number or
string but it just throws an exception.

Any help would be much apprisiated.

NB
Dec 19 '07 #2
You are not going to be able to make this component work in a Windows
Forms app.

When you call CreateObject on the server, it detects the presence of
this method, and passes the ASP (not ASP.NET) context to the object to be
created (and this seems odd, quite honestly, since you only have one ActiveX
exe running, it could have the context changed often).

When you just call new, it will create the object like it normally does,
without looking for the OnPageStart method.

To get around this, you will need to change the code in the ActiveX exe
to not try and access the intrinsic ASP objects (server, request, response)
if the OnPageStart method is not created.

Curious, why was this created as an ActiveX exe in the first place? Why
not as an in process server?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"NvrBst" <nv****@gmail.comwrote in message
news:41**********************************@d21g2000 prf.googlegroups.com...
On Dec 18, 12:43 pm, NvrBst <nvr...@gmail.comwrote:
>My problem is that it keeps returing nothing after calling the
methods. I "TlbImp.exe TEST.exe /out:TESTCS.dll" and then in C# Right
click Add Reference Browse and give it the TESTCS.dll.

It adds "TESTCS" and I can use intellasence to see all the methods. I
do

TESTCS.Flower myFlower = new TESTCS.Flower();
MessageBox.Show(myFlower.get_GetFlower(2));

The "myFlower.GetFlower(2)" COM is suppose to return the 2nd flower
(stored in registry), which is a string. When I do this it says to
call accessor method directly "myFlower.get_GetFlower(2);" and this
just returns null.

I can use the COM EXE from my ASP/JScript pages using "object myFlower
= Server.CreateObject("TEST.myFlower);" and "myFlower.GetFlower(2);".
Just doesn't want to work in a Windows Form C# App.

Any suggestions? I've tried late binding, it seems more complicated
and I don't need late binding but it doesn't work either. Late
Binding code below:

Type objClassType;
objClassType = Type.GetTypeFromProgID("TEST.myFlower");
object objApp_Late = Activator.CreateInstance(objClassType);
objApp_Late.GetType().InvokeMember("GetFlower",
BindingFlags.InvokeMethod, null, objApp_Late, new object[] {55555});

It crashes at runtime with a "TargetInvocationException: Exception has
been thrown by the target of an Invocation." on the last line.

Thanks NB

Update: Reasion its not working in the C# Application is because the
"CmyFlower::OnPageStart(IUnknown* piUnk) {...}" isn't being called
automatically. I created an ASP.NET/C# page and in the default
codebehind file I make a function

public string GetFlower(){TEST.Flower myFlower = new TEST.Flower();
return myFlower.get_GetFlower(2);}

And in my form I do "<% Response.Write(GetFlower()); %>" But I still
only get null because a varible in the COMs "OnPageStart(IUnknown*
piUnk)" method isn't getting set. Does "new TEST.Flower();" not call
that function automatically like "Server.CreateObject("TEST.Flower");"
does?

I don't mind calling the "OnPageStart(IUnknown)" manually but I'm
unable to find what they want as the arg ("piUnk"). My ASP.NET Code
behind file extends System.Web.Page so I think I should have the
"piUnk" they want someplace... I tried giving it a random number or
string but it just throws an exception.

Any help would be much apprisiated.

NB

Dec 19 '07 #3
On Dec 19, 12:35 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
You are not going to be able to make this component work in a Windows
Forms app.

When you call CreateObject on the server, it detects the presence of
this method, and passes the ASP (not ASP.NET) context to the object to be
created (and this seems odd, quite honestly, since you only have one ActiveX
exe running, it could have the context changed often).

When you just call new, it will create the object like it normally does,
without looking for the OnPageStart method.

To get around this, you will need to change the code in the ActiveX exe
to not try and access the intrinsic ASP objects (server, request, response)
if the OnPageStart method is not created.

Curious, why was this created as an ActiveX exe in the first place? Why
not as an in process server?

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"NvrBst" <nvr...@gmail.comwrote in message

news:41**********************************@d21g2000 prf.googlegroups.com...
On Dec 18, 12:43 pm, NvrBst <nvr...@gmail.comwrote:
My problem is that it keeps returing nothing after calling the
methods. I "TlbImp.exe TEST.exe /out:TESTCS.dll" and then in C# Right
click Add Reference Browse and give it the TESTCS.dll.
It adds "TESTCS" and I can use intellasence to see all the methods. I
do
TESTCS.Flower myFlower = new TESTCS.Flower();
MessageBox.Show(myFlower.get_GetFlower(2));
The "myFlower.GetFlower(2)" COM is suppose to return the 2nd flower
(stored in registry), which is a string. When I do this it says to
call accessor method directly "myFlower.get_GetFlower(2);" and this
just returns null.
I can use the COM EXE from my ASP/JScript pages using "object myFlower
= Server.CreateObject("TEST.myFlower);" and "myFlower.GetFlower(2);".
Just doesn't want to work in a Windows Form C# App.
Any suggestions? I've tried late binding, it seems more complicated
and I don't need late binding but it doesn't work either. Late
Binding code below:
Type objClassType;
objClassType = Type.GetTypeFromProgID("TEST.myFlower");
object objApp_Late = Activator.CreateInstance(objClassType);
objApp_Late.GetType().InvokeMember("GetFlower",
BindingFlags.InvokeMethod, null, objApp_Late, new object[] {55555});
It crashes at runtime with a "TargetInvocationException: Exception has
been thrown by the target of an Invocation." on the last line.
Thanks NB
Update: Reasion its not working in the C# Application is because the
"CmyFlower::OnPageStart(IUnknown* piUnk) {...}" isn't being called
automatically. I created an ASP.NET/C# page and in the default
codebehind file I make a function
public string GetFlower(){TEST.Flower myFlower = new TEST.Flower();
return myFlower.get_GetFlower(2);}
And in my form I do "<% Response.Write(GetFlower()); %>" But I still
only get null because a varible in the COMs "OnPageStart(IUnknown*
piUnk)" method isn't getting set. Does "new TEST.Flower();" not call
that function automatically like "Server.CreateObject("TEST.Flower");"
does?
I don't mind calling the "OnPageStart(IUnknown)" manually but I'm
unable to find what they want as the arg ("piUnk"). My ASP.NET Code
behind file extends System.Web.Page so I think I should have the
"piUnk" they want someplace... I tried giving it a random number or
string but it just throws an exception.
Any help would be much apprisiated.
NB- Hide quoted text -

- Show quoted text -
My apologies. The ActiveX EXE was created for a web site, however, I
was running into problems with getting the COM object to work with the
ASP.NET/C# pages so I made a new C# App and thought if I got it workin
in this I'd get it working for the ASP.NET/C# (I'm more confortable in
C# App than ASP.NET/C#). I made a new blank ASP.NET/C# page and
working with that now (moved this topic to ASP.NET section).

Thanks very much for the reply :)
Dec 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
3
by: Mike L | last post by:
Should the command call "using" be before or after my namespace? **AFTER** namespace DataGridBrowser { using System; using System.Drawing; using System.Drawing.Drawing2D; using...
3
by: xzzy | last post by:
I was wondering why we have to have using System.Data using System.Configuration using etc.... why are they not all lumped into one 'using'? In other words, is there a best way to use...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
8
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
10
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.