locked
Getting an exception "Method's type signature is not PInvoke compatible" when try to use c++ runtime component from c# metro app.

    Question

  • my C++ header file having below code:

    public value struct SpapWPRCData sealed
    {
    int returnCode;
    Platform::String^spapString;
    Platform::String^strPoint;
    Platform::String^strEncPoint;
    };

        public ref class SpapWPRTComponent sealed
        {
        public:
            SpapWPRTComponent();
    SpapWPRCData WprcSecurePapEncrypt( String^ algorithm, String^ public_key,String^ password,String^ dialer_id,String^ counter,String^ point,String^ ePoint);
        };

    and trying to invoke from c# like this:

    [StructLayoutAttribute(LayoutKind.Sequential)]
        public struct SpapWPRCData
        {
            public int returnCode;
            [MarshalAsAttribute(UnmanagedType.ByValArray)]
            public string spapString;
             [MarshalAsAttribute(UnmanagedType.ByValArray)]
            public string strEncPoint;
              [MarshalAsAttribute(UnmanagedType.ByValArray)]
            public string strPoint;
        }


        public static class ManagedSpapWrapper
        {

            internal const string SpapWinPRCLibPath = @"SpapWinPRCLib.dll";

            [DllImport(SpapWinPRCLibPath, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
            public static extern SpapWPRCData WprcSecurePapEncrypt(string spapAlgorithm, string publicKey, string currentPwd, string dialerID, string dialerCounter, string strPoint, string strEpoint);

    }

    What could be the possible issue with marshelling of data ? Plese help.

    Sunday, May 18, 2014 7:22 AM

Answers

  • You can't build AnyCpu when you have a native component. You will need to build targeting the same architecture as the component.

    • Marked as answer by rajeev.ipass Monday, May 19, 2014 3:48 PM
    Monday, May 19, 2014 2:55 PM
    Moderator

All replies

  • You don't pinvoke runtime components. Once referenced you call them like normal classes.

    var snap=new SpapWPRTComponent();
    
    snap.WprcSecurePapEncrypt(...)
    

    See http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh755833.aspx

    Sunday, May 18, 2014 12:11 PM
    Moderator
  • I already tried this but i was getting error:

    Error 40 The processor architecture of your project 'neutral' doesn’t match the processor architecture 'x64' of the referenced project 'SpapWinPRCLib'. Change the targeted processor architectures to align between your project and its references.

    that's why move to PInvoke. any idea how to resolved this issue.


    Monday, May 19, 2014 6:15 AM
  • You can't build AnyCpu when you have a native component. You will need to build targeting the same architecture as the component.

    • Marked as answer by rajeev.ipass Monday, May 19, 2014 3:48 PM
    Monday, May 19, 2014 2:55 PM
    Moderator
  • thanks Rob.

    it is working now.

    Monday, May 19, 2014 3:49 PM