|
for instance, there is a method in COM named f defined as followed
void f()
{
__try
{
int* pInt = NULL:
*pInt = 0;
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
printf("exception!\n");
}
}
when I call f(), an exception is raised and the programe crash.
|
|
|
|
|
That's COM? Mmmmm.
denghp wrote: int* pInt = NULL:
*pInt = 0;
Look at your code. You're writing to a null pointer. Yes, you get an access violation. What is pInt meant to point at?
The problem you need to solve is not catching the exception - your problem is rewriting the code so it doesn't cause the access violation in the first case.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I just want to test if __try and __except is in effect, so I write codes like that.The result is it doesn't work.
|
|
|
|
|
So....your question had nothing to do with COM...OK
Anyway - I wrote this sample program:
#include <windows.h>
#include <iostream>
int f()
{
__try
{
*(int*)0 = 0;
std::cout << "good!\n";
}
__except( EXCEPTION_EXECUTE_HANDLER)
{
std::cout << "exception!\n";
}
return 3;
}
int main()
{
f();
}
and compiled it with VS2008 using the command cl -EHa a.cpp (you apparently need -EHa for structured exception handling to work correctly).
As expected, it printed exception! - the structured exception handler was called correctly.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
OK,I will check my project configuration.Thank you very much.
|
|
|
|
|
Hi,
I think you should through the exception from you COM+ function, & show / manage detail from where you call the function. Like
Try
{
}
Catch(Exception ex)
{through ex;}
Thanks
Md. Marufuzzaman
|
|
|
|
|
Hi
I haven an ATL COM in-proc server which is crashing randomly. I would not say it as a crash, the server just vanishes after running successfully for 9-10 hours. And then restarts immediately on the next call to CreateInstance() by the clients. I am unable to debug as this is not a crash and happening randomly. Though I'm not providing much details as the code base is huge, any thoughts just to start with would be very much appreciated. I observed that FinalRelease() was called before the server vanishes, but for the initial 10 hours many clients have called FinalCOnstruct() and FinalRelease() without any issues.
Thanks in advance
Harish
|
|
|
|
|
Harish Pulimi wrote: the server just vanishes after running successfully for 9-10 hours
I don't understand what you mean by this. How did you reach such conclusion?
As I interpret your complete description it seems like you're describing the expected behaviour.
I'm quite confident that clients don't call FinalConstruct() or FinalRelease() through any interface. Those functions are called internally by the framework. FinalConstruct() is called when the server is created by a client and FinalRelease() is called when the reference count reaches zero and the server consequently should be destroyed.
This means that if you're experiencing a lot of calls to FinalConstruct() and FinalRelease() your server is being created and destroyed multiple times by its client.
If this is not your intention, I suggest you put a breakpoint in FinalRelease() and you should be able to see the origin of the call in the call stack debug window when the breakpoint is hit. It looks like you expected the server to be created once and then stay alive until the application is closed, but this doesn't seem to be the case given your error description.
Perhaps I have misunderstood what you mean by "vanish" and if that's the case please elaborate on the subject a bit. It could mean that CreateInstance() fails after 9-10 hours, but I think you would have written that as a description of the error if this was the case.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi Roger
Thanks a lot for your reply and apologies for not providing more details.
The architecture is like I have an exe which keeps track of all the servers that will be created by the clients through CreateInstance() calls. This exe needs to run all the time and if not already started, it will start through the next CreateInstance() call made by a client. The problem is that the exe runs fine for around 10 hours and after that it suddenly vanishes i.e. the process just stops, there is no crash reported and the exe immediately starts with the next CreateInstance() call but loses all the previous data. This happens only on some PCs, so I tried putting my debug build on that PC, but still there is no exception, no crash reported, so I thought this could be a heap corruption.
To reproduce this, I have created a test harness where around 100 clients continously bombard the exe with CreateInstance() calls and I could get an exception as follows, not sure whether this is the same crash but it seems like similar to the actual problem. Any idea how to debug the exceptions in OLE32.dll?
First-chance exception in AniteLicenser.exe (OLE32.DLL): 0xC0000005: Access Violation.
OLE32! 77600f3b()
OLE32! 77600ee9()
OLE32! 77600ba0()
OLE32! 7752ad31()
OLE32! 7752ac56()
OLE32! 776007f5()
OLE32! 77602df3()
OLE32! 77600715()
RPCRT4! 77e794bd()
RPCRT4! 77e79422()
RPCRT4! 77e7934e()
RPCRT4! 77e8a384()
RPCRT4! 77e8a3c5()
RPCRT4! 77e7bcc1()
RPCRT4! 77e7bc05()
RPCRT4! 77e76caf()
RPCRT4! 77e76ad1()
RPCRT4! 77e76c97()
KERNEL32! 7c80b713()
One time I could get the following call stack, seems something is going wrong in the Release() call, but the same exe runs fine for around 10 hours (100s of instances were created and released successfully in the meantime) and on a different PC, this exe ran fine for around 3 days:
ATL::_QIThunk::Release(ATL::_QIThunk * const 0x0171d440) line 2734 + 11 bytes
OLE32! 7750d339()
OLE32! 7750d09a()
OLE32! 7752deb3()
OLE32! 7752dcc8()
OLE32! 7752db6a()
RPCRT4! 77e799f4()
RPCRT4! 77ef421a()
RPCRT4! 77ef4bf3()
OLE32! 77600c15()
OLE32! 77600bbf()
OLE32! 7752ad31()
OLE32! 7752ac56()
OLE32! 776007f5()
OLE32! 77602df3()
OLE32! 77600715()
RPCRT4! 77e794bd()
RPCRT4! 77e79422()
RPCRT4! 77e7934e()
RPCRT4! 77e8a384()
RPCRT4! 77e8a3c5()
RPCRT4! 77e7bcc1()
RPCRT4! 77e7bc05()
RPCRT4! 77e76caf()
RPCRT4! 77e76ad1()
RPCRT4! 77e76c97()
KERNEL32! 7c80b713()
|
|
|
|
|
Harish Pulimi wrote: apologies for not providing more details.
No worries. There's no point in posting a lot of details before it's clear what to provide the details for.
I don't really understand your architecture and how this mysterious "exe" keeps track of the running servers. It seems like the "exe" is a COM server itself....
Harish Pulimi wrote: I have an exe which keeps track of all the servers
How is this accomplished if CreateInstance() isn't called from this "exe" in order to create the other servers?
Harish Pulimi wrote: This exe needs to run all the time and if not already started, it will start through the next CreateInstance() call made by a client.
How is the "exe" started?
Is it an out-of-process COM server and "started" with CreateInstance() ?
Perhaps you should consider to have it running as a service.
If the "exe" is an out-of-process COM server that doesn't run as a service, it is quite expected that it will terminate if its reference count reaches zero unless you've provided functionality to prevent it.
The call stack snippets you've provided implies that the call to the server is made in an RPC-thread which means that you're using a multithreaded solution.
In such case it's fairly reasonable to suspect thread synchronization issues, but first we have to agree on how the apartments are set up. So I have a couple of questions for you...
- Are you certain that every thread that uses any kind of COM related stuff contains a call to
::CoInitialize() or one if its equivalents? - Are you certain that every thread that instantiates a COM server has a message pump that will not be blocked?
- What threading model have you registered below the server entry in the registry?
In other words; what value is assigned to the registry value "ThreadingModel" in the registry entry HKCR\CLSID\{<your server CLSID>}\InprocServer32 ? - How is the apartment initialized from which you create the server?
I suspect it is initialized as a multithreaded apartment. - Are you using proper marshalling? How?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Finally found the bug. In the client code COM library was not being initialized properly.
Because of this, it is unable to tear down the connection to the server. Now everything works as expected.
|
|
|
|
|
Can you please share this solution with more details? I am seeing the similar kind of issue, and unable to drill down to root cause and solution.
--Ashish
|
|
|
|
|
How can we determine the sizeof object from the interface pointer?
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
No, not unless the interface in question exposes a method for it.
An interface pointer is just what it says - a pointer.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
You don't. What's more, if you want to you're misunderstanding COM.
Steve
|
|
|
|
|
Stephen Hewitt wrote: What's more, if you want to your misunderstanding COM.
Nice. Can you tell that to the guy in my thread just below?
|
|
|
|
|
Sometimes there is no object behind the interface pointer at all, only the set of functions.
With best wishes,
Vita
|
|
|
|
|
Hello,
i need to convert a system.__comobject to a byte[] in C# .Net
greetings,
Sander
|
|
|
|
|
Sander1234321 wrote: i need to convert a system.__comobject to a byte[] in C# .Net
I suppose if you know the size of the com object in bytes you can marshal the memory into managed memory, however my guess is that is not what you want.
|
|
|
|
|
i tried that with the following code:
int structsize = System.Runtime.InteropServices.Marshal.SizeOf(obj);
but it raises an error namely: "Type 'System.__ComObject' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed."
greetings,
Sander
|
|
|
|
|
Sander1234321 wrote: but it raises an error namely: "Type 'System.__ComObject' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed."
DUH, that's why I said:
led mike wrote: I suppose if you know the size of the com object in bytes
I also said:
led mike wrote: however my guess is that is not what you want.
I have nothing new to add so this post is completely redundant.
|
|
|
|
|
I have written a COM DLL which gives the
out parameter as BSTR**(Typically 2D Char Array).
This COM function will fill the values of BSTR** variable.
I am able to use this function sucessfully in MFC Application.
But I face problem in using it in C#.
The Sample code is as follows:
///////////COM Function////////////////////////////////////////
STDMETHODIMP CSampleTest::GetAllDeviceList2(BSTR** szMaclist)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
for(int i=0;i<10;i++)
{
szMaclist[i] = new BSTR[100];
wchar_t *szTmp = new wchar_t[100];
wsprintf(szTmp,L"Device%d",i+1);
*szMaclist[i]=SysAllocString(szTmp);
}
return S_OK;
}
///////////////////////////////////////////////////////////////
I acessed this in VC++ by,
BSTR **szMaclist = new BSTR*[10];
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,iid,(void**)&pText);
if( SUCCEEDED(hr) )
{
pText->GetAllDeviceList2(szMaclist);
pText->Release();
}
and i am sucessful in acessing this function in MFC Application.
Can anyone tell me how to acess GetAllDeviceList2() function in c#.
|
|
|
|
|
Try using SAFEARRAYs rather than standard C arrays. That way, there should be metadata in the type library or something that can help the process.
This CP article[^] might help
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.TypeInitializationException: The type initializer for 'AMP.mdlCaiDat' threw an exception. ---> System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
at AMP.mdlCaiDat..cctor()
--- End of inner exception stack trace ---
at AMP.mdlCaiDat.InsertTimeAll(String idcard, String TimeInOut, String tablename, Byte TongSLC)
at AMP.mdlFnRac.FN_save(Byte p_id)
at AMP.frmRac.btnDownloadData_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
AMP
Assembly Version: 2.0.0.1
Win32 Version: 2.0.0.1
CodeBase: file:///D:/PM%20cham%20cong%20AMP/Chuong%20trinh/AMP.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
KTMDK
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/PM%20cham%20cong%20AMP/Chuong%20trinh/KTMDK.DLL
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
Interop.Excel
Assembly Version: 1.5.0.0
Win32 Version: 1.5.0.0
CodeBase: file:///D:/PM%20cham%20cong%20AMP/Chuong%20trinh/Interop.Excel.DLL
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
|
|
|
|
|
Error 0x80040154 indicates you haven't registered your COM component. Registration-free COM interop[^] might be want you want.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|