开发者

How to use P/Invoke regarding multiple classes in one .dll?

I am fairly new to using P/Invoke. So I am able to use P/Invoke currently using this way as said in Microsoft Tutorial:

[DLLImport("msvcrt.dll")]
public static extern int puts(string c);

then just call

public void UsePuts()
{
  puts("Testing");
}

However, I am now testing on the actual .dll that I want to use. And I found out by looking at the source code, that it seems that in that one .dll file, there are multiple classes (like Class1.cpp and Class2.cpp).

So for example, I want to use a function from Class1 (puts), and a function from Class2(puts开发者_如何学Python), how should I build my DLLImport? Like this?

[DLLImport("msvcrt.dll")]
public static extern int Class1.puts(string c);
[DLLImport("msvcrt.dll")]
public static extern int Class2.puts(string c);

Or how? Thanks very much!


Check this sample

public class LibWrap
{
    /*
    class PINVOKELIB_API CTestClass 
    {
        public:
            CTestClass( void );
            int DoSomething( int i );
        private:
            int m_member;
    }; 
    */
    [ DllImport( "..\\LIB\\PinvokeLib.dll", 
    EntryPoint="?DoSomething@CTestClass@@QAEHH@Z", 
    CallingConvention=CallingConvention.ThisCall )]
    public static extern int TestThisCalling( IntPtr ths, int i ); 
    // CTestClass* CreateTestClass();
    [DllImport( "..\\LIB\\PinvokeLib.dll" )]
    public static extern IntPtr CreateTestClass(); 
    // void DeleteTestClass( CTestClass* instance )
    [ DllImport( "..\\LIB\\PinvokeLib.dll" )]
    public static extern void DeleteTestClass( IntPtr instance ); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜