Calling a COM Object with a LPWSTR ** param from C#

J

Jinhee Myoung

I wish to call a COM Object which has a parameter of type
LPWSTR ** on a method call from C#

The COM Method :-

STDMETHODIMP CClassType::GetDataInfo(LPWSTR ** ppData)
{
......

return S_OK;
}

How do I create the parameter required within C# in order
to call this COM Method.
I've read quite a few postings on marshalling and the
such, but is there anyone that can explain this in simple
terms or code samples would be good.

I think my main problem is C# knowledge, as I have only
just started using it TIA for even the smallest hint on
how to resolve this problem.
 
D

Daniel Bass

I assume the following:
- this is a COM object created in C++ (hence macros like LPWSTR etc)
- you are using VS.Net when compiling c# (if you're not, you can skip to
the last couple of paragraphs)

In VS.Net if it's a COM object, then all you need to do is this:

1. Ensure the COM object is registered (in the registry, with RegSvr32)
2. In your project, you go to the "Solution Explorer", and right click on
"References".
3. select "Add Reference".
4. then you'll have a few tabs, with the current being ".Net", with others,
"COM", and "Projects".
5. Your object should be in the list that is in the COM tab, if it's not,
click on the "Browse" button and locate the DLL/OCX instead.
6. Once you've found it, click "Select" so that the item appears in the list
of "Selected Objects"
7. OK.

Now you'll see that a "MyCOMClass" reference has been added to the
references, you can include this in any class by using the "using" keyword.

What just happened?

Well you got VS.Net to create an interop between the COM object and your
code. This means that your code, running on the .Net Intermediate Language,
is not able to communicate with "unmanaged" C++ code (your C++ COM object
falls into this group). So VS.Net created another DLL, that is a mediator
between the COM object and the IL, so that your .Net project can use it.

Now if you're not using VS.Net, you have to do this manually, but it's
easier that it seems given the .Net framework tools.
I'd recommend reading the MSDN stuff on this:
http://msdn.microsoft.com/library/d.../html/vcwlkCOMInteropPart1CClientTutorial.asp
(beware of line wraps)

Hope that helps and I didn't completely miss the boat.
Dan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top