|
Hello,
I am facing problem while calling CoInitialize().
Here is the sample code:
ABC.exe
=======
for (int i = 0; i < 150; i++)
{
if (!SUCCEEDED(::CoInitialize(NULL)))
{
MessageBox(NULL, "CoInitialize Failed", "Failed", 0);
}
COleMessageFilter* pTempObj = new COleMessageFilter;
BOOL bResult = pTempObj->Register();
::CoUninitialize();
}
XYZ.exe
=======
In XYZ.exe i am invoking ABC.exe for more then 750 times.
After invoking around 500 exes, there is an error for CoInitialize .
If i put a sleep of 1 second in for loop, then there is no error.
I have simulated my problem using the above sample code.
In fact, I am getting error as 0x80070583 and system error as 1411 (Class does not exist).
Thanks in Advance!
Regards,
Tony
modified on Monday, July 12, 2010 12:07 AM
|
|
|
|
|
Hi.
I have a piece of code at client side which calls a method of a COM server to create and return an object. While trying to assign values to data members of this object, I get the following exception - "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I don't have much exposure to COM so am quite clueless as to how to solve this. Parts of the source are pasted below.
<IDL>
interface _ICallInfo: IDispatch
{
[
propget,
id(1),
helpstring("Call ID")
]
HRESULT CallId([out, retval] LONG *pVal);
[
propput,
id(1),
helpstring("Call ID")
]
HRESULT CallId([in] LONG nCallId);
[
propget,
id(2),
helpstring("Barge Call")
]
HRESULT CallType([out, retval] LONG *nCallType);
[
propput,
id(2),
helpstring("Call Type")
]
HRESULT CallType([in] LONG nCallType);
};
dispinterface _IApplication
{
[
id(3),
helpstring("method CreateCallInfo")
]
HRESULT CreateCallInfo([out]_ICallInfo** piResult);
};
<Client side - a C# client>
public void foo()
{
CallInfo callInfo = null;
CreateCallInfo(out callInfo);
try
{
callInfo.CallId = this.CallId;
callInfo.CallType = (int)this.CallType;
}
catch (Exception ex)
{
//Exception here
}
}
Any help will be appreciated.
Thanks.
|
|
|
|
|
1. What is the actual code for the following function?
HRESULT CreateCallInfo([out]_ICallInfo** piResult);
2. Why do you not check the result of your CreateCallInfo(out callInfo); call to see whether your object was actually created?
It's time for a new signature.
|
|
|
|
|
Richard MacCutchan wrote:
1. What is the actual code for the following function?
HRESULT CreateCallInfo([out]_ICallInfo** piResult);
void CApplication::CreateCallInfo(IDispatch** piResult)
{
CCmdTarget* pTarget = new CCallInfo();
*piResult = pTarget->GetIDispatch(TRUE);
}
I am not sure if you need the source for CCallInfo class so skipping that.
Richard MacCutchan wrote:
2. Why do you not check the result of your CreateCallInfo(out callInfo); call to see whether your object was actually created?
Sorry about skipping that part. I actually do check for that and I am a 100% sure that 'callInfo' has been created successfully. The thing is we have been using 'Reflection' to copy data to 'callInfo' till date. Now we plan to remove that as we are finding it a bit heavy.
Please do let me know if more information is required.
|
|
|
|
|
I notice that the declaration of the CreateCallInfo shows it to return a HRESULT but the implementation is void so there is no way you can check the return value. Also within this function you have no error checks. It may be best to add some more code into your catch block to try and identify which memory pointer is invalid. If this is easily reproducible then the debugger should be the way to go.
It's time for a new signature.
|
|
|
|
|
Caught! I actually don't do that but I knew that there is no problem in creating the 'callInfo' object as I was checking that using the debugger (always reproducible if I don't use reflection to assign values). This is how the function looks like using reflection (which works without a hitch) -
<pre>
public CallInfo CreateCallInfo(ApplicationClass appRoot)
{
CallInfo callInfo = null;
//callInfo = new CallInfo();
appRoot.CreateCallInfo(out callInfo);
try
{
Type typeCallInfo = typeof(CallInfo);
Type typeUCOMCallData = typeof(UCOMCallData);
object[] objValue = new object[1];
foreach (PropertyInfo pi in typeUCOMCallData.GetProperties())
{
objValue[0] = typeUCOMCallData.GetProperty(pi.Name).GetValue(this, null);
typeCallInfo.InvokeMember(pi.Name,
BindingFlags.SetProperty,
null,
(CallInfo)callInfo,
objValue);
}
}
catch (Exception ex)
{
}
}
</pre>
Trying without reflection -
<pre>
public CallInfo CreateCallInfo(ApplicationClass appRoot)
{
CallInfo callInfo = null;
//callInfo = new CallInfo();
appRoot.CreateCallInfo(out callInfo);
try
{
//Type typeCallInfo = typeof(CallInfo);
//Type typeUCOMCallData = typeof(UCOMCallData);
//object[] objValue = new object[1];
//foreach (PropertyInfo pi in typeUCOMCallData.GetProperties())
//{
// objValue[0] = typeUCOMCallData.GetProperty(pi.Name).GetValue(this, null);
// typeCallInfo.InvokeMember(pi.Name,
// BindingFlags.SetProperty,
// null,
// (CallInfo)callInfo,
// objValue);
//}
callInfo.CallId = nCallId; //private member variable
}
catch (Exception ex)
{
}
return callInfo;
}
</pre>
Checking value of 'callInfo.CallId' in debugger gives me this -
callInfo.CallId = 'callInfo.CallId' threw an exception of type system.AccessViolationException'
and the exception described earlier.
Hope this makes it clearer to understand my problem.
Thanks.
|
|
|
|
|
Trying to paste more information about the exception from the exception helper
System.AccessViolationException was caught
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="WebAstra.Application.VoIP.UniversalCOMServer.Interop"
StackTrace:
at WebAstra.Application.VoIP.UniversalCOMServer.Interop._ICallInfo.set_CallId(Int32 pVal)
at WebAstra.Application.VoIP.UniversalCOMServer.UCOMCallData.CreateCallInfo(ApplicationClass appRoot)
Now the dispatch map for this in source is like:
BEGIN_DISPATCH_MAP(CCallInfo, CCmdTarget)
DISP_PROPERTY_ID(CCallInfo, "CallId", dispidCallId, m_nCallId, VT_I4)
END_DISPATCH_MAP()
In the sources, I don't see any function of setting or getting values so I tried using DISP_PROPERTY_EX_ID instead of DISP_PROPERTY_ID with get and set functions but that didn't change anything.
(my change which didn't change anything)
DISP_PROPERTY_EX_ID(CCallInfo, "CallId", dispidCallId, GetCallId, SetCallId, VT_I4)
Moreover in the interop, I do see the entry like this -
[DispId(1)]
int CallId { get; set; }
Maybe that's because get and set methods have been declared in the IDL file (??).
Thanks.
|
|
|
|
|
I don't see anything in the above that offers a clue. My only suggestion is to step through the code with the debugger and trap where the exception occurs. You should then be able to see the actual memory that is causing the problem.
It's time for a new signature.
|
|
|
|
|
asr1122 wrote: void CApplication::CreateCallInfo(IDispatch** piResult)
{
CCmdTarget* pTarget = new CCallInfo();
*piResult = pTarget->GetIDispatch(TRUE);
}
Return of IDispatch pointer is not equal to return of _ICallInfo pointer. IDispatch pointer does not have the CallId property (more clearly, the CallId get-property and CallId put-property), presented in _ICallInfo dual interface.
You can heal this by:
1) replacing of "interface _ICallInfo: IDispatch" onto "dispinterface _ICallInfo" in IDL file;
2) replacing of "*piResult = pTarget->GetIDispatch(TRUE);" onto "*piResult = GetInterface(&__uuidof(_ICallInfo))" or "InternalQueryInterface(&__uuidof(_ICallInfo), piResult);" with acceptable casts.
With best wishes,
Vita
|
|
|
|
|
Thanks for the suggestion. I couldn't make it work though. Decided to give up on this way of passing data. Looking at other simpler options.
Thanks for the help.
|
|
|
|
|
HI,
I faced this question in an Interview,
"Difference between COM Component and Class"
What is the Answer.
Thanks & Regards,
Rayalu
|
|
|
|
|
In basic terms a COM component exposes a binary interface which allows a program written in any language to access it, regardless of the language that the component is written in. A class is exposed as source code and can only be used in a program using the same source language.
It's time for a new signature.
|
|
|
|
|
|
You're welcome; good luck in your interviews.
It's time for a new signature.
|
|
|
|
|
Hello Experts,
I am using WScript.Shell to read some values from the Windows Registry. I have seen that the RegRead() method returns the value of the Key. But I need to read all the SubKeys of a given Key.
For example, I want to read all the SubKeys under HKLM\Software . Some of the SubKeys under this path are: "Microsoft", "Windows", "Intel", "Licenses" etc. I want to read them.
Can anyone please suggest how I can do this using the COM API? Any help regarding this is highly appreciated.
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
The RegEnumKeyEx API will enumerate all subkeys under a registry key.
To use this using the Shell object, you will need to write an application using C/C++ and then call it using the Exec method.
|
|
|
|
|
Thanks for the reply, but I don't want to use C/C++. I want to use it in Silverlight to call the COM API to read the registry values. Any URL/Tutorial/CodeSnippet will be helpful.
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
Hello people!
I am quite new to OLE programming and need a kick in the right direction. I tried to google this up but i lack proper knowledge to know what to search for in the first place, so i thought i ask here. So this is basicly what i want to do: I want to create an object that can be inserted into any document like word documents, excell sheets, or anything else that can be an IOleContainer. This object would containa certain kind of data that is inserted into it from an external file. This data should be saved along with the document containing this object (so not hang around as an external file). The object would serve as a "data source" for a few kinds of views. The user should somehow be able to "spawn" such views from the object and edit these to generate different types of representations of the data. He should also be able to perform a few operations on these views that would add additional information the the source data and this additional information could be used in other views as/if needed.
E.g: the user inserts this object into his word document, then double clicks this objects and gets a little GUI where he can add the data from the file system and/or specify some additional information. After adding the data and dismissing this GUI he right-clicks the objects and selects "Span View", gets a list where he can select the type of view, let's say "red diagram", "green diagram", "blue diagram", after selecting the type the view somehow gets inserted into the same document the object is on. After having multiple views, he can select one of these views, edit its appearance as he wants and also add some more information which gest stored inside the source object and the other views also get notified by this and update themselfs as needed.
This might be a trivial, everyday task for you fellas but as i said, i am new to this and needs some directions.
Thanks for any help attempts in advance, feel free to ask if there's something that is not clear about the whole concept.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Hello,
I need to look up the registry for checking whether a given COM Dll/Exe registered or unregistered? Whether registry contains the entries for that COM DLL/EXE or not?
Programatically how can I be able to do that?
Regards
Usman
|
|
|
|
|
COM components are register under the registry key HKEY_CLASSES_ROOT\CLSID .
For example ole32.dll is registered in HKEY_CLASSES_ROOT\CLSID\{00000319-0000-0000-C000-000000000046} .
So to check if the key exists you can use the RegOpenKeyEx API on this key.
If the API returns success, it means the key exists.
Don't forget to close the key using RegCloseKey .
|
|
|
|
|
Hi,
I hope this is the correct place to post this, I could not find anywhere more suitable.
I just started using Visual Studio 2010, and I thought that some of my old addins from previous versions might be useful to me.
The ones I want generally do things outside of VS, so the bulk of the code should be OK.
Problem is, I have come up against the #includes for header files in the older VS ObjModel/ directory, and also it is full of 'I' prefixed things, like IApplication, IConfiguration, ITextDocument, etc... which obviously do not exist in the VS 2010 world.
Is there any Tutorial that explains how to update these addins to a later release, like Visual Studio 2010?
I guess that many of you have had to go through this process at some time.
Many thanks for any help.
Bryan.
|
|
|
|
|
COleInsertDialog is use to read contents of any doc,pdf,xls etc file. This class open a dialog box and allow to select a file to read its contents.
Is there any other OLE class (or COleInsertDialog) which do not require a dialog box to select a file and read its contents. To read any file data it will take a buffer (any char/wchar array) which contains file data.
Without selecting a file name if i have some file contents in a buffer then which OLE class use this buffer to read the data.
|
|
|
|
|
I have a com server. And i implimented a client to access the server.The code looks,
int main(int argc, char* argv[])
{
::CoInitialize (NULL);
CComPtr<INextGen> pINextGen;
pINextGen.CoCreateInstance (CLSID_Server);
int val;
pINextGen->GetNum (&val);
cout<<val;
::CoUninitialize ();
return 0;
}
This code is giving run time error, when the destructor of CComPtr is called.If I remove ::CoUninitialize() it is not giving the error. How to solve the problem?
Regards,
venkatanarayana
|
|
|
|
|
Release your interface pointer before you return.
pINextGen->Release();
Think you'll find that the problem is with your Interface object when it's being destroyed.
|
|
|
|
|
Hello Friends
I have creared one .jar file with java NetBeans.Now,i want to use this jar file functionalities in c# application.So,I want to register jar file as COM object so that i can use it.
So,is there any way to register as COM object in System Registery?
I found one way thru google is to register thru javareg.exe but I didnt found the javareg.exe.
Do you have any other Ideas?
Thanks In Advance.
Regards
Yogesh Sikri
|
|
|
|