COM Interop - Cannot instantiate objects

  • Thread starter Thread starter Bobby C. Jones
  • Start date Start date
B

Bobby C. Jones

I'm trying to use some classes defined in a COM component that I did not
create. I have successfully created the RCW via Tlbimp.exe and referenced
it in my project. All is well until I run the project and it chokes with an
"Invalid access to memory location." error when I try to instantiate an
object like so:

AecXSchedule30.AecAnchorTagToEntClass anchor = new
AecXSchedule30.AecAnchorTagToEntClass();

I'm not sure where the best place for me to start looking for the answer
lies. I'm currently pouring over more COM Interop doc material than I ever
even wanted to know existed. Am I missing something so basic? Anybody have
a clue as to where I should start looking? Thanks.
 
Bobby,

The two things I can think of off the top of my head are a) is the
object properly registered on the machine you are running this on and b)
have you set the threading model of the current thread correctly?

Hope this helps.
 
Nicholas,
A) I have some VB6 code that consumes it with no problem, so I know that
it's registered properly.

B) I haven't set up any threads if that's what you mean.

I'm still looking over COM Interop docs and finding nada.

Thanks again!
 
Are you using Visual Studio? If yes, you can try to right click on your
project in solution explore, and select "Add Reference". Select "COM" in the
shown dialog. Pick your COM object, you will be able to use it like any
class.

This is most fool proof way to use COM object in C#. Nerver have any problem
to me.
 
I found the problem and it had absolutely nothing at all to do with the RCW.
It was my own mistake elsewhere, imagine that. Thanks for all your help.
 
Back
Top