 |

|
Hi Atul Mani,
I want to rasie events from C# COM DLL and handle them in unmanaged C++ client. Please if you have any sample let me know.
Many Thanks
IK
|
|
|
|

|
MyDotNetClass has a single constructor. Is it possible to implement more constructors and call any of these constructors from C++ code?
Regards,
Mike
modified 17 Jul '12 - 10:21.
|
|
|
|

|
Hi,
thanks for a very nice article. this was really very useful.
If any one can guide on what needs to be done in the installer so the these binaries can be used in the installed location.
Regards
Sandeep
|
|
|
|
|

|
This is a great, compact article that is still relevant today.
I found doing this in Visual Studio 2010 that it wasn't necessary to create an SNK (also bug with step 13 with having AssemblyKeyFile in Assembly.cs), nor was it necessary to call GACUtil as jive_b noted 2012.Jan.25).
Given the article's usefullness so many years on, perhaps update this? Either way...'bump' and thanks!
|
|
|
|

|
It's worth pointing out (which also kind of answers Member3156877's post) it's not actually necessary to install the assembly into GAC. Using the GAC can be an unnecessary hassle with deployment due references being to a particular version, not to mention getting assemblies in there in the first place.
To register assemblies not in the GAC and get the tlb use:
REGASM /codebase blar.dll /tlb:blar.dll.tlb
|
|
|
|
|

|
Hi, this is an excellent article that helped me build a managed component and call it from a legacy VC++ application. But how to build the release versions of the components and deploy this managed component in production? Not all the production PCs have gacutil. thanks in advance.
|
|
|
|

|
Call_CSharp_COM.vcproj is not included in the project?
|
|
|
|

|
I have prepeared project folllowing instrctions given in this article(Calling Managed .NET C# COM Objects from Unmanaged C++ Code
).I have used VS 2008 and .Net Framework 2.0 for both projects.Issue I have is I am not getting interfaces in namespace while trying to acces in C++ project
MyInterop::IMyDotNetInterfacePtr pDotNetCOMPtr; .I am not getting IMyDotNetInterfacePtr in namespace.ALos I loked into .tlh file of C++ project it is also not having any defination of interfaces.
Please let me know what I am missing?
|
|
|
|

|
I have the same problem ... did you find the solution ?
Thanks
|
|
|
|

|
Check your .tlh file in OLE viewer , you will find definations of the methods declared in interface.
To access interfaces from C# DLL they have to be first listed in .TLH and .TLB.
Delete old .tlb and .tlh and den check also clear there copies from ~\temp directory.
|
|
|
|

|
This is well documented and helped me for my projects
|
|
|
|

|
Hi, Have you ever observed, in the above process after creating CoCretingInstance the memory in the task manager went up and even though you called CoUnitilize it wont come back to normal. Do you have any inputs on this?
Thanks and Rgds,
VamsiDhar.MBC
SoftwareEngineer.
|
|
|
|

|
Has anybody found a solution to the memory leaking issue ? I too have seen this behavior, and I'm not sure how to fix it.
|
|
|
|

|
I can compile the C++ code in Visual C++ 2008.
BUt I can't compile it using Dev-C++.
How do I make it compatible with Dev-C++?
|
|
|
|

|
This post was driving me insane because it wasn't working. Then I found another similar tutorial on MSDN. In this other tutorial, they used the public keyword before the interface and class name in the c# project. Once I added the keyword and repeated the rest of the steps, it worked fine.
|
|
|
|

|
I should have said "class" definition instead of "call" definition...
|
|
|
|

|
Indicar el link de donde encontraste la solucion del proyecto, porque tambien me esta volviendo loco
|
|
|
|

|
Hello,
the example is very good and solve a lot of problem for me. But my question is, what is, if the path to the tlb is different from pc to pc. Some users can install my software on c:\ or d:\ but in my code i write the path to the tlb hard into it. Have anyone a idee, how i can solve this? Can i write the path into the registy an import the path from registry? Some idee?
Thx.
|
|
|
|

|
Hi,
I followed your instructions and everything worked well. Thanks for article but I have a problem at client side actually. I copy my .tlb file to another computer and try to call it from a C++ project and when i'm creating instance of my com object, it returns "HRESULT = 0x80040154"
Any idea?
Thanks.
|
|
|
|

|
how would i implement basic properties in the c# dll
and access them in native , sounds simple i know but i having problems with types, my property int in C# is being seen as a long*
dont get it , how do i do it ?
|
|
|
|

|
Please let me know how to handle the events raised by .NET object in C++ code.
|
|
|
|

|
Hi,
its a very useful example. But I have a question:
Do I have to install the assembly in the GAC to use it with COM?
Regards Markus
|
|
|
|

|
If you get this error message when you try this example for yourselves, try this:
- Open your C# project
- Go to your project's properties (right-click menu)
- Under the Build tab, make sure the "Register for COM interop" is checked (both for Debugging AND Release)
You might have to redo steps 14 and 15:
- Add your assembly to the GAC
- Register your assembly for COM by using the REGASM
And then try running your C++ again
Hope it saves some of you lots of trouble!
|
|
|
|

|
Hi,
Please help me I am getting this exception
When trying to create interface this error occurs i.e hres is not S_OK :-
Unhandled exception at 0x7c812a5b in DotNet_COM_Call.exe: Microsoft C++ exception: _com_error at memory location 0x0012fd5c..
PLz tell me where I am wrong as most of ppl have succeded while trying this example...
Thanx in advance.
modified on Monday, September 22, 2008 8:53 AM
|
|
|
|

|
I can use it with Debug mod but in Release mod it can't find the C# com
How can I do?
|
|
|
|

|
How do you debug this code? Lets say from my C++ client, from where I create this .NET object and then call the MessageBox.Show() function. If I place a break point in the C++ code how do I trace it to the .NET function
|
|
|
|

|
'namespace::interfaceName' : cannot instantiate abstract class
...
..
HRESULT IUnknown::QueryInterface(const IID &,void **)' : is abstract
etc etc
If someone get these errors on compiling Call_CSharp_COM.cpp,
then replace _tmain() body with this one...
CoInitialize(NULL); //Initialize all COM Components
CComPtr<namespaceName::interfaceName> pPtr;
HRESULT hr = pPtr.CoCreateInstance(namespaceName::CLSID_classname);
if (hr == S_OK)
{
pPtr->ShowDialog();
//call .NET COM exported function ShowDialog ()
}
CoUninitialize (); //DeInitialize all COM Components
Hope it helps.
the fruits of your success will be in direct ratio to the honesty and sincerity of your own efforts in keeping your own records, doing your own thinking and, reaching your own conclusions.
..surviving in autumn..in love with spring..
modified on Friday, July 4, 2008 10:32 AM
|
|
|
|

|
I do get this error, but CComPtr is undefined in your fix. Where does CComPtr come from?
|
|
|
|

|
you may need to include atlbase.h [^]
check where CComPtr is defined. You should use smart pointers with directshow. it will save you from lot of headache.
|
|
|
|

|
i followed the example and did some of the corrections (lyk making the interface public, set Register for COM Interop to TRUE, etc.) but still im not able to run the console application...when i compiled the it, i got these errors:
error C2039: 'CLSID_MyDotNetClass' : is not a member of 'MyInterop'
error C2065: 'CLSID_MyDotNetClass' : undeclared indentifier
has anyone run into this problem?
tnx
|
|
|
|

|
it should be CreateInstance("namespace.classname").
stepping into CreateInstance, you will know what it needs.
|
|
|
|

|
I have the same problem:(
|
|
|
|

|
After compling this #import “<Full Path>\com.MyInterop.tlb" named_guids raw_interfaces_only
com.MyInterop.tlb file is not getting created
|
|
|
|

|
I'm geting
Cryptographic failure while signing assembly 'C:\Documents and Settings\joxyej\Desktop\ManagedCOM\ManagedCOM\MyInterop\obj\Debug\MyInterop.dll' -- 'Error reading key file 'MyKeyPair.snk' -- The system cannot find the file specified. '
error ...pls help
|
|
|
|

|
I had a similar problem i ended up changing the place where the key was then the error went away.
|
|
|
|

|
jus create the .snk file
using this command (from Visual studio command )
first go to the path and thn
sn -k TestKeyPair.snk
and add this in your assembly file
[assembly: AssemblyKeyFile("TestKeyPair.snk")]
|
|
|
|

|
For some reason the compliler says that the CLSID_MyDotNetClass is undefined in the following line:
pDotNetCOMPtr.CreateInstance(MyInterop::CLSID_MyDotNetClass);
Has anyone run into this problem?
Thx
|
|
|
|

|
hi erick,
i'd lyk to ask u f ur able to solve this error?
i encountered this problem also.
|
|
|
|

|
This old, but i had the same problem.
The solution is: use #import with named_guid.
Compile one time and the IDE knows the constants.
|
|
|
|

|
I have created a C# Class Library(MyInterop.dll) for COM Interop.
I have COM dll where in i need to retrieve the CLSID using LoadTypeLib() followed by GetTypeAttr()
LoadTypeLib("MyInterop.dll", &typeLib);
typeInfo->GetTypeAttr(&typeAttr);
clsid = typeAttr->guid;
But the call to LoadTypeLib returns TYPE_E_CANTLOADLIBRARY.
(Pls note that i dont want to use #import .tlb")
Your help is appreciated
Thanks
|
|
|
|

|
It won't work, if your .NET component makes use of .NET licensing, and most commercial ones do, because it this case the client must be signed as well. Getting C++ application signed seems tricky. Do you know how to do it? Too bad you didn't cover it here...
Free C++ libraries with source code on www.neatcpp.com: TWAIN, DirectShow, Interprocess Communications, etc...
|
|
|
|

|
How it looks? Is it special error code or what? Im getting error "cannot instantiate abstract class" continiously on my own project like this one above.
|
|
|
|

|
It has been a while since i tried the last time, so i can't remember what error code was exactly, but i think that was one of license failure.
After I contacted the .NET component's manufacturer we were able to work it out in a tricky way. I wrote my own C# component that used their component, while my C# COM component was used from a C++ client via COM. In order to make it work I had to add a special attribute in my own C# component where I initialized the commercial component, and that attribute somehow allowed their license to be treated as internal to their component only, without trying to spread its requirements through the sub-hierarchy of clients, and then it worked.
|
|
|
|

|
I did as the above steps. But when I run the samples, the "CreateInstance()" shows that the class is not registered. Why ? Is there anyone who can help me out?
|
|
|
|

|
After a full days searching and reading this is what fixed it for me.
Changed build events to read.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\gacutil.exe /i "$(TargetPath)"
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe "$(TargetPath)" /tlb:"$(TargetDir)com.MyInterop.tlb" /codebase
|
|
|
|

|
Hi, I have the same problem, but the solution does not work for me.
Any body have a working solution using VS2005? Please give some detailed steps. Thanks a lot!!!
|
|
|
|

|
Hi all,
I also have the problem, that my class seems to be not registered in the right way. When I call CreateInstace, it says: class not registered. I use Fwk 2.0, used gacutil.exe and regasm.exe in v2.0 and registered them according to the instruction given in the article.
In my class however, there are members and constructor-calls of other classes, which were NOT registered for COM (ComVisible(false)).
Could it be, that I mustn't uses those members and classes in my COM class?
Thanks for your reply,
beni
|
|
|
|

|
Found this while looking for more information on the topic. Hope others find it useful as well: http://support.microsoft.com/kb/828736
|
|
|
|
 |