473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

creating an activeX component at runtime

Hi,

I have a C# application (VS2005) with Microsoft Mappoint activeX control on
a form. At a certain moment I want to create a second one temporary in code.
This seems not to work, when I try to access it I have an InvalidActiveXState
Exception.

I cannot find mutch on the web about this Invalid State of a component
except that it is invalid (what the Exception already describe). So I hope
someone here knows ?

It cannot be difficult to create an ActiveX component at runtime ? Are there
special things to do with it except calling the constructor with New ?

--
rgds, Wilfried
http://www.mestdagh.biz
Aug 18 '06 #1
4 6762
Wilfried,

I'm not sure exactly what you have to do, but, if I was facing this, I
would look at the area in the designer code and see how it is instantiating
the control, and see if there is a difference in the way that you are doing
it, versus how the designer is doing it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wilfried Mestdagh" <Wi**************@discussions.microsoft.comwrote in
message news:3C**********************************@microsof t.com...
Hi,

I have a C# application (VS2005) with Microsoft Mappoint activeX control
on
a form. At a certain moment I want to create a second one temporary in
code.
This seems not to work, when I try to access it I have an
InvalidActiveXState
Exception.

I cannot find mutch on the web about this Invalid State of a component
except that it is invalid (what the Exception already describe). So I hope
someone here knows ?

It cannot be difficult to create an ActiveX component at runtime ? Are
there
special things to do with it except calling the constructor with New ?

--
rgds, Wilfried
http://www.mestdagh.biz

Aug 18 '06 #2
Wilfried Mestdagh wrote:
Hi,

I have a C# application (VS2005) with Microsoft Mappoint activeX control on
a form. At a certain moment I want to create a second one temporary in code.
This seems not to work, when I try to access it I have an InvalidActiveXState
Exception.

I cannot find mutch on the web about this Invalid State of a component
except that it is invalid (what the Exception already describe). So I hope
someone here knows ?

It cannot be difficult to create an ActiveX component at runtime ? Are there
special things to do with it except calling the constructor with New ?
Hi,

from my experience this can come from one or both of two things.

A lot of ActiveX controls require a call to BeginInit before you access
its properties:

AxHost activeX = ...;
activeX.BeginInit()
// do something
activeX.EndInit();

The second thing is that some ActiveX controls need to have a parent to
work correct. (After all they are ActiveX controls).

AxHost activeX = ...;
activeX.BeginInit()

// parent the control
Controls.Add(activeX);

activeX.EndInit();

This however will make the control visible.

HTH,
Andy
Aug 18 '06 #3
Hi,

Thank you. It was the Controls.Add() that did it. I set Visible to false and
it is ok too. I use it in a using block to make suer it is disposed.

--
rgds, Wilfried
http://www.mestdagh.biz
Aug 19 '06 #4
Wilfried Mestdagh wrote:
Hi,

Thank you. It was the Controls.Add() that did it. I set Visible to false and
it is ok too. I use it in a using block to make suer it is disposed.
Hi,

if you are using .NET 1.1: We have found a memory leak when we dispose
ActiveX controls. Depending on the size and type of your ActiveX and how
often you create/dispose it, you might want to do something about it.

The ActiveX hooks the VisibleChanged event of the main form when added
to another control and does not unhook it on Dispose(). This means that
the ActiveX will not be garbage collected as long as the main form
lives. If your ActiveX releases all resources on dispose properly, you
only will only notice a increase on the GC Handles.

One solution would be to keep he control creates and invisible. Another
one is to unhook the event using reflection.

This issue seems to be fixed in .NET 2.0.
Cheers,
Andy
Aug 19 '06 #5

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

Similar topics

1
by: Mattt | last post by:
Hi, I've run into a rather odd problem. get Methods seem to return values from the wrong methods! For example, let's pretend my activex control stores values about a person. getName would return...
0
by: Joe | last post by:
I've been running into problems when trying to create a Virtual FTP folder in ASP.Net. I've tried it a few ways but none of them has worked so far. I have identity impersonation turned on, and the...
19
by: Steve | last post by:
Can anyone point me to a primer for creating OCX controls in VB .net? In particular, I want to access a web service in a VB6 application (not an easy thing to do). So, if I can write an ActiveX...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
1
by: Casper | last post by:
I am issuing the following commands in a form's detail on click event. Private Sub Detail_Click() Dim Nline As Line Set Nline = New Line I get :"ActiveX component can't create object" ...
1
by: Raed Sawalha | last post by:
Hello I have ActiveX DLL and I usually register it using following procedure 1. gactutil -i ActiveXDLL 2. regasm ActiveXDLL /tlb:DLLNAME/codebase 3. then using the activeX can I automate step...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
1
by: Rocio | last post by:
I have a windows app. written in VB6, now we need to expose some of its classes through a web service. I am only able to expose the classes using late binding becasue that's the way the original...
6
by: hufaunder | last post by:
I have an ActiveX component that I want to use in a library that I am writing. As a first test I used the ActiveX component in a windows form application. Adding the component created: Ax.dll...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.