|
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
|
|
|
|
|
I was trying to write COM wrapper for a 3rd party .net library (basically wrote few functions based on that library). So, I followed all the steps given in the msdn site, and VB6 IDE was detecting it fine and all the implemented functions were showing up correctly, but there is one problem. Nothing was working and program was crashing at point where those functions were referenced, because it just see the wrapper but doesn’t find the actual library, My question is, what I am doing wrong? Is there any way I can wrap my COM wrapper and library together?
Thank you,
Arya
|
|
|
|
|
Dear all,
I am having an out of memory problem in Matlab with using a proprietary DLL to read data that was recorded using that company's software and equipment.
I have went through the problem with the software engineer at the company and he is quite certain that it is not due to leaking memory because the DLL only creates the memory object once and reuses it.
The DLL (data reader) is loaded using the actxserver command in matlab. The DLL retrieves data based on events, so I registered the event using: registerevent({'DataReady' 'DataReady_function'});
That is, when the user asks for data, the DLL sends it back via the event callback function in Matlab: 'DataReady_function'.
I have inserted "clear VARIABLES" throughout the functions to ensure that I have cleared all variables that were no longer used. When the data came in via the event handler as "varargin", I even loaded everything in (i.e., FULL_DATA = varargin) and taken out the data (i.e., Data = varargin{7}) and then applied "clear" to the whole "varargin" (i.e., clear FULL_DATA).
The problem is that as I loop through the function, reading through the stored data on the hard drive, more and more memory gets held up by Matlab, even though I am not actually storing any data within Matlab (just consistently reading in small bits of data and then clearing it). If I let it keep running, Matlab eventually runs out of memory. If I stop it before it runs out and try to "clear all", Matlab still holds onto the memory and will not release it (I confirmed this by looking at the memory usage under the processes tab in Windows Task Manager).
From what I can gather, Matlab must be trying to protect all the bits of data that comes in via the event callback, but I just don't know how to tell Matlab that the data has been read and it does not need to protect it any longer. If you have encountered this problem or know how to resolve it, please let me know.
I am really stuck and would really appreciate your help. Thank you very much.
Yours sincerely,
Alan
|
|
|
|
|
LaiAlan wrote: I am having an out of memory problem in Matlab
How have you verified this?
Did MatLab crash due to low memory or did it display a message that told you it was running low on memory?
If you base all this on the figures in Task Manager you should really have a look at this article[^].
LaiAlan wrote: If I let it keep running, Matlab eventually runs out of memory.
Have you actually experienced this?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Yes, Matlab crashed due to low memory. The actual error message is:
??? Out of memory. Type HELP MEMORY for your options.
Error in ==> comeventcallback at 3
args = hEvent.get;
Warning: Error occurred while evaluating listener callback.
After it has ran out of memory and stopped "reading and clearing data" (i.e., I did it to make sure it doesn't use more and more memory), "clear" did not change the memory used by Matlab at all:
>> memory
Maximum possible array: 8 MB (8.389e+006 bytes) *
Memory available for all arrays: 69 MB (7.256e+007 bytes) **
Memory used by MATLAB: 2767 MB (2.901e+009 bytes)
Physical Memory (RAM): 3326 MB (3.487e+009 bytes)
|
|
|
|
|
LaiAlan wrote: ??? Out of memory. Type HELP MEMORY for your options.
Error in ==> comeventcallback at 3
args = hEvent.get;
Warning: Error occurred while evaluating listener callback.
This looks interesting. It looks like an error message from MatLab
To me it seems reasonable that such an error won't occur unless the application is trying to allocate memory. The text "Error occurred while evaluating listener callback", makes me suspect that this error occurs before your callback is called.
The above suggests that MatLab is allocating memory internally prior to calling your callback. This could be due to how the callback interface is declared.
What does the callback interface look like? Post the declaration of it.
If you don't allocate any memory in your callback and the third party DLL doesn't allocate memory when calling your callback, then it must be some kind of internal MatLab stuff that is going on and it should be possible to find in the MatLab documentation.
Have you tried writing another client to avoid MatLab related stuff with e.g. MFC?
What happens?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Dear Roger,
Thank you very much for your reply.
The following is a section of the code in the Connect.m function that does all the initialisation (creates the actxserver, opens the data file using a method of the DLL, creating the data reader interface and registering the event callbacks to retrieve data):
%--------------------------------------------------------------------------
% Load Study Interface (ACTUALLY, it is a COM Server in Matlab, not an
% interface).
gIStudy = actxserver('CMEEGStudyV4.Study');
% Open the study.
gIStudy.Open(FilePath,0) % File path name
% Determine the sampling rate and the number of channels in the study.
SampleRate = gIStudy.get('EEGSampleRate');
gSampleRate = SampleRate;
IChannels = gIStudy.get('Channels');
TotalChs = IChannels.count;
clear IChannels
gTotalChs = TotalChs;
% Determine how many data segments there are in the study.
IDataSegs = gIStudy.get('DataSegments');
NumDataSegs = IDataSegs.count; % A data segment is like a 'Block' in TDT.
% The data segments' start times are all referenced to a single time point.
% That is, the second data segment's start time is always later than the
% first data segment's start time plus the first data segment's duration.
% Create the Data Reader (Interface).
DataReader = gIStudy.CreateDataReader;
DataReader.registerevent({'DataReady' 'DataReady_TEST'});
DataReader.registerevent({'NoData' 'NoData_TEST'});
%--------------------------------------------------------------------------
I have a Get_Data.m function that the user specifies the start time and duration of the data required from the data file. The Get_Data.m function has a line of code that uses the data reader in the DLL to request the data:
%--------------------------------------------------------------------------
DataReader.SGetDataEx(StartSample,NumberofSamples);
while ~gDataRetrieved % gDataRetrieved is a global variable
pause(0.0001) % Stay in this while loop until all the data has been retrieved.
end
gDataRetrieved = false; % Reset the DataRetrieved flag
%--------------------------------------------------------------------------
In the event callback function (DataReady.m), all it does is read in the data:
%--------------------------------------------------------------------------
gDataMat = varargin{7}; % When a registered event is triggered, Matlab passes information
% from the event to its handler function as a cell.
% It is the 7th cell because 1-2 are Matlab stuff.
% 3-6 are some data info retrieved by the DLL.
I have narrowed down the source of the problem by using the Matlab "memory" command throughout the functions. In particular,
memory usage = 518MB
memory (i.e., "memory" command before the datareader line)
DataReader.SGetDataEx(StartSample,NumberofSamples) % This will trigger the DataReady.m to read data
memory usage = 597MB
Just as it enters the DataReady.m function (i.e., "memory" command as the 1st line of function)
memory usage = 597MB
As it exits the DataReady.m function (i.e., "memory" command as the last line of function)
memory usage = 545MB
DataReader.SGetDataEx(StartSample,NumberofSamples)
memory (i.e., "memory" command after datareader line)
So, it has leaked 545MB - 518MB = 27MB per data retrieval cycle. I think I might have mentioned it before, but using "clear" will not reduce the memory that Matlab holds up, as opposed to, say:
memory usage = 900MB
x = randn(10000,10000);
clear
memory usage = 100MB
Yes, your suggestion of using another client is an excellent idea, although I am not much of a programmer (only a little C programming from undergraduate studies, which I have forgotten). I don't know what MFC is. Will look into your suggestion.
Thanks,
Alan
|
|
|
|
|
Hi to all,
I am creating a IE toolbar in C#, using Band Object.
I want to get event or any attribute value, which show that is my toolbar is enable/disable in IE.Or which event/attribute of band object tell me the satus of my toolbar.
Please Help me.
|
|
|
|
|
Only way I know is to check registry key
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Ext\Settings\<GUID>, where <GUID> is your toolbar CLSID. If value 'Flags' exists in this key, then your toolbar is disabled. If Flags value does not exists or whole key does not exists - your toolbar is enabled.
|
|
|
|
|