Creating pointer causes illigal memory access

Hello

I need to wrap some functions from the Insigth Toolkit in my own DLL.
This is generally no problem.
I create a class whith some methods that uses the toolkits functions.
Then I create some functions that will interact with the objets of my class; and only this few functions I export with dllexport.
(Some kind of wrapping...)

This all works fine.

But I need some pointer to use in every method. So my idea was following:

Answer this question

Creating pointer causes illigal memory access

  • JulieMcB

    when you call identifySet()

    Kuphryn


  • uniquegodwin

    I wrote a small Windows Forms (managed C++) application to access the proxy functions of my DLL.
    The proxy function looks like that:

  • richie_crazy57

    Hi

    After endless hours of headache I realised where I make the mistake.

    The SmartPointer of ITK lives only at the scope of a method.

    Unlike most other instances in ITK, SmartPointers can be allocated on
    the program stack, and are automatically deleted when the scope that the SmartPointer was
    created is closed.

    Now I'm in trouble, I need this pointer as an global variable.

    I have to figure out this...

    Thanks Kai

  • Joffies

    To debug, build your application (the EXE and DLL) under debug mode, and run the EXE using F5. When exceptions occur, the debugger should take you the line causing the problem. If the exception occurs in a DLL for which you don't have source code, you'll only get to see disassembly.

    You can use the call stack window to trace the sequence of function calls that led to the exception.

    You can watch variables using the debugger obtain their values.

    Now that I see you are using a smart pointer, I rescind my suggestion about using new or making it a member of the class. The implementation probably depends on New() being called.

    Brian


  • vivek25

    reader = MyReader::New() where reader is a class data member is expected to be valid. The debugger has access to symbol information for reader, see if its implementation is based on reference-counting (usu. the case for smart pointers), and that the ref-count >=1 when your methods goes out of scope.


  • besserer

    Are you using a debugger   Let the debugger take you to the point of the exception, and then deduce backward what the cause is.

    Other ideas (your code seems convoluted):

    Instead of ReaderType::Pointer reader;
    how about ReaderType* reader;

    Instead of reader = ReaderType::New();
    how about reader = new ReaderType();

    Instead of ReaderType::Pointer reader;
    and reader = ReaderType::New();
    how about
    ReaderType reader;
    (i.e. just make the reader a member of your class, rather than a pointer to a reader that you later allocate).

    Brian

     


  • Creating pointer causes illigal memory access