none
DllImport Attribute problem RRS feed

  • Question

  • hi,

    i have a c++ dll i want to use that dll in console application

    so i used DLLImport attribute class

    but i don't know where to keep that dll

    my samples code is as follows

     [DllImport("sample.dll", CharSet = CharSet.Unicode)]
            public extern static Int32 sampleVersion(ref UInt16 aMajor,
                                                         ref UInt16 aMinor,
                                                         ref UInt16 aPatch,
                                                         ref UInt16 aBuild);

    i am getting loading DLL problem. can you please tell me where to keep that DLL


    thanks, prathap If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, January 22, 2013 6:07 AM

Answers

All replies

  • "can you please tell me where to keep that DLL"

    The c++ dll should be in the same directory as the C# console application. If that doesn't work for you then show some details about the error you are getting.

    Tuesday, January 22, 2013 9:26 AM
    Moderator
  • i added assembly .but i was getting other error

    A call to PInvoke function 'ConsoleApplication1!ConsoleApplication1.Program::APIWrap_InitialiseTheApiFwk' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.


    thanks, prathap If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, January 22, 2013 9:55 AM
  • Well, the error message is quite explicit, your PInvoke method doesn't match the C++ one. So the C++ declaration of the method.

    Tuesday, January 22, 2013 9:57 AM
    Moderator
  • Hi Prathap,

    >>but i don't know where to keep that dll

    Please register it into your machine by Regsvr32 tools: http://msdn.microsoft.com/en-us/library/ms859484.aspx 

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 23, 2013 10:45 AM
    Moderator