|
Thanks,
I had a look at the link you said, it helped a bit but I still can't get around this problem.
It seems like the form runs in STA mode but the class that is set to handle callbacks is set to MTA mode. I have tried to set the Apartment mode to STA in the callback class but it just throws the error: "Can not set to STA" or something along those lines.
As you can see I'm not 100% sure where I have to set the class to run in STA mode. I have tried to put the <stathread> above Main in both in the form and in the Class but no luck .
Can anyone help me on this one?
P.S I'm using VB.NET if I havn't said before
|
|
|
|
|
MadmanWoo wrote: In the Callback class I have a sub set up to handle every time the OLE window changes which works fine, now the fun begins. I set up another sub which takes a string from the sub receiving the callback message, it then uses this string to select a control on the main form like so
Dim pnl as Panel = Mainform.pnlLegend.Controls.Item({String})
When ever it gets to this line it throws the error "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made".
I believe the problem happens because your callback and the control, whose property you are setting, are in different appartments. Will it help if you make the call from your event handling sub to another sub as non blocking instead of a blocking call - post the string to a queue or post the reuquest to your UI thread etc
What appartment mode does your main thread run in?
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
I have created a COM based application using DLL server.But i havn't used server as type of EXE.I don't know the exact difference when i will have to use DLL Server or EXE Server with COM base application.
Plase reply me as soon as possible.
Thanks & Regards
Pankaj
Regards,
Pankaj Sachdeva
|
|
|
|
|
DLL-based COM objects will load into the calling application's process. If you implement an EXE server, COM will start your EXE as a separate process. This should be transparent to the calling application. The main difference is that it will take much longer to call code running in another process than code running in your own process.
To actually call code in another process, or another apartment in the same process, COM must marshal the call parameters across the process or apartment boundary. This means writing out all the parameters, and any other areas of memory they reference, to some transport (e.g. a block of shared memory) and somehow signalling the other process that there is a call for it to handle. When the actual function returns, COM must then marshal the results back to the caller. To do this, it has to know the actual data types and whether a pointer represents a string, an array, or just a single object (and if a string or array, how long the string or array is), and whether the parameters are passed in only, passed out only or passed both in and out.
Marshalling can proceed in three ways:
1. The object implements the IMarshal interface;
2. A proxy/stub class is registered for the interface in the registry;
3. A type library is registered to use the Automation marshaller.
Option 3 is really a special case of option 2 - the Automation marshaller is registered as the proxy/stub class. It then looks up the correct type library and uses the information in that to perform the marshalling. This is the most limited option, however. You can only use the Automation data types and structures containing those types. The upside is that scripting languages like VBScript can use your components.
In general, for option 2, you don't actually write your own code for the proxy/stub class. Instead, you define your interfaces in IDL and pass them through the MIDL tool, which generates either tables describing the interfaces or code. The tables have been supported since Windows 98 and Windows NT 4.0, and an update is available for Windows 95 that supports them. All you have to do is build the code into a DLL; Visual Studio generates a project file for you.
COM gets the class factory object for a class implemented in a DLL by calling the DLL's DllGetClassObject function. It cannot call directly into an EXE's code, so the EXE must instead register its class factory objects, for classes that can be created externally, using the CoRegisterClassObject function.
EXE servers are mainly used for implementing OLE and Automation in desktop applications, and where isolation between the client and server is necessary (perhaps for security reasons). If the former, the application typically implements a command-line option (typically /embedding ) to indicate that it was launched by COM, not by the user, and to hide its user interface in response.
Finally, it's possible to make a DLL server run in another process if it's registered as a COM+ Server Application. I'm not sure whether doing this with an arbitrary DLL is a good idea, it is probably best to use a component only how the author intended it to be used (as it is unlikely that they have tested other scenarios).
|
|
|
|
|
I am trying to capture video from web cam.I am using ICaptureGraphBuilder2.
I am getting compilation error
'ICaptureGraphBuilder2' : missing storage-class or type specifiers
'CLSID_CaptureGraphBuilder2' : undeclared identifier
I am using VC6 and visual studio 2003
I have install the directx sdk
I have include the dshow.h
I have included the lib files in project settings.
Quartz.lib Strmiids.lib strmbasd.lib wmvcore.lib wmstub.lib Msvcrtd.libWinmm.lib
I have included the paths in the tools->options->directories
but after doing all this I am getting this compilation error messages. Please any body help me.
S.Yamini
|
|
|
|
|
How to Generate OLE dispatch map functions using class wizard or using any other.
please help.
|
|
|
|
|
Hi all,
Thanx in advance.
|
|
|
|
|
|
1.I am working on win professional xp with regional settings changed to chinese(RPC)
2.I added a custom property in chinese alplabets to a word file from windows explorer.
3.I want to read the Custom Properties of a word file.
4.I got the root storage by StgOpenStorage and finally got the pointer to IPropertyStorage.
5.Now when i read custom property using ReadMultiple, i get invalid characters for the custom Property
6.Note:This happens only for custom properties.
Please let me know the solution of the problem.
Thanks and Regards!
Hands-down one of the best
|
|
|
|
|
Hi, i have an ir receiver connected at serial port. i
want to receive signal at serial port using vb.net. is there any sanple code available or any one who can help me.
Thanks
-Waqas
|
|
|
|
|
This will help[^]
Please do not post same question on multiple forums. Since it's a VB.net question, post only in VB.NET forum.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
The question describes as follows:In CxxActiveXCtrl I declare a member m_dlgMain for a dialog which was produce for display the picture and In CxxActiveXCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) function I wrote "m_dlgMain.Create(IDD_MAINDIALOG,this);",then in the dialog's OnInitDialog() procedure I use IPicture to display the specified picture,the display codes is correct,but can see nothing in the html,while move the codes to the dialog's OnDraw() it works ok,I suppose the dialog doesn't notify the control to erease the background but I've written InvalidRect(TRUE) after display.What's the matter?
|
|
|
|
|
why the Exception Retrieving the COM class factory for component with CLSID failed due to the following error: 80004005. occurs how to resolve this.
|
|
|
|
|
Possibly an exception is being thrown from the class constructor. If you have source code for the component, please check the constructor.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
I have this same problem did you resolve this issue and how I'd appreciate any feedback.
Thanks in advance,
Michael
|
|
|
|
|
Does anyone know tutorial of how to create plugin for Mozilla?(I was thinking activeX but it doesn't support it)
It needs to be in C++ and should be able to read from the registry
Thanks
|
|
|
|
|
XPCOM[^]is what you need to know.
S o h a i l K a d i w a l a
To Err Is Human; to Debug, Divine
modified 21-Apr-21 21:01pm.
|
|
|
|
|
This should be pretty easy but I'm having so many problems with it.
I'm following someone elses code and cant figure out how he did this.
One of the webmethods returns 3 parameters and it uses a class of somesort to do it. We had to reverse engineer to get the code so its not complete.
[WebMethod]
Public Class1 HelloWorld(int i1, string str1, string str2)
{
try
}
//Code
}
Catch
}
return Class1(1,2,3)
}
{
return Class1(0,0,0)
}
}
How is this possible? Thanks in advance.
|
|
|
|
|
If you declare the class with the Serializable value then ASP.NET will take care of translating it into an XML datatype when it is returned. The added benefit of returning the class, besides returning multiple values, is that the XML elements will have the same name as the fields which in this example are Field1, Field2, and Field3.
<br />
[Serializable]<br />
public class Class1<br />
{<br />
private string _field1;<br />
private string _field2;<br />
private string _field3;<br />
<br />
public Class1()<br />
{<br />
}<br />
<br />
public Class1(string Value1, string Value2, string Value3)<br />
{<br />
this._field1 = Value1;<br />
this._field2 = Value2;<br />
this._field3 = Value3;<br />
}<br />
<br />
public string Field1<br />
{<br />
get { return this._field1; }<br />
set { this._field1 = value; }<br />
}<br />
<br />
public string Field2<br />
{<br />
get { return this._field2; }<br />
set { this._field2 = value; }<br />
}<br />
<br />
public string Field3<br />
{<br />
get { return this._field3; }<br />
set { this._field3 = value; }<br />
}<br />
<br />
}<br />
|
|
|
|
|
The question describes as follows:the embeded system which has a apache service installed, capture picture and sound file from the usb camera.I use the activex control to show the picture and play the sound,how can my control to get the data the apache sent?
|
|
|
|
|
Hi experts,
I have a problem...
I am creating an ActiveX component (my first) and in it I need to call a third party dll from a program. the function works only if the program is active.
So basically: my activeX should just post message to the program to execute one of its functions; if the program is active, should execute the order, if not I will use my ActiveX to tell the user that the application is not active
Thank you in advance for all your comments
Dimkov
|
|
|
|
|
I have created simple ATL project. Using AddClass i have added ATL Control object which has a stock property 'Fillcolor' then finished the wizard. After that i tried to add property by using 'add propery', its creating necessary entries in IDL file but its not creating get and set methods to the implementation file.
why this happens? Please help me.
I also find that if i add stock propery to the ATL Control only the above problem occurs.
|
|
|
|
|
Hi,
Is there someone who knows if it's possible and how to integrate COM in a XBAP wpf application?
I've made a wrapper and when I tried to make an instance to it I 've got an AccesViolationException. In my desktopapplication this exception doesn't occur and everything works well. But when i tried it in a browser and in a mediacenter application, this exception was thrown. I think it has to do with the security of web applications but I'm not sure.
Elke.
|
|
|
|
|
Hello
I have developed a COM server using attributed ATL with VS8. The objects are instantiated and used within a C# .NET Windows Forms application. When shutting down the application not all FinalRelease() methods of all objects can execute completely. I can make this behaviour constant by placing a call to Sleep(5000) at the beginning of the FinalRelease() method, the execution will never reach the next statement.
The debugger says at this point that the lowest frame on the call stack is "[In a sleep, wait or join]" (independently from the additional Sleep() call that is not executed at this time).
I think it is related to the threading model of my COM objects (apartment). Someone (I don't know exactly who) waits an amount of time for my objects to terminate and then forces termination. But I don't want this behaviour! How can I disable that or set the timeout to another value? (I'd prefer INFINITE!)
What is the reason for the described behaviour? How can I solve the problem without adding cleanup functions that are called before any descruction code? (I thought FinalRelease() is actually such a cleanup function )
Best regards
Steve
|
|
|
|
|
I think your problem here is actually in how the .NET Framework uses COM objects.
When you create a COM object in .NET code, the Framework generates something called a Runtime Callable Wrapper. The Framework does not call AddRef on your component every time the .NET code makes a copy of the interface pointer. It only calls Release when it destroys the RCW. Instead, it performs traced references with the garbage collector - if the GC detects there are no outstanding references to the RCW it then marks it for collection.
So what calls Release ? I'm not too sure on this one, but I think the RCW ends up on the finalization queue, and then the finalization thread is responsible for calling Release . Unfortunately, there is a total of one finalizer thread in the system (separate from all the application threads, so you can get cross-threading problems) and it can easily get blocked.
I think what's happening for you is that the finalizer thread isn't being allowed to run to completion on process shutdown.
My personal best practice is to do everything possible to avoid finalization. That means calling Dispose on everything as soon as I've finished with it - the using block in C# (and VB 8.0) can help a lot here. Unfortunately again, the RCW doesn't implement IDisposable and cannot be disposed of in this way.
The only documented way to dispose of a COM object explicitly is to call Marshal.ReleaseComObject . However, this function does not trace references and can prematurely delete an object that is still actually in use, so use it carefully.
It is probably better to add an explicit way of allowing the client to close down the object, rather than relying on FinalRelease .
|
|
|
|