Using <DllImport("dmsgen.dll")> _ with projectwise dll's

Hello,

  I'm trying to use VB.net with projectwise ,I tried to add some dll's from projectwise explorer to my project but it cause an error of "a refrence to this file couldn't be added please make sure this file is accessible and that is a valid assembly or com component", So I tried to use <DllImport ("dmsgen.dll")> _ then write functions but the datatypes cause errors example(LPCWSTR  and LPCWSTR) Any help about that??

Thanks,

Walaa

Parents Reply Children
  • Hi Anwar,

     Again if you are using VB.NET and use the <DLLImport> it will Marshall the values passed between Managed and Unmanaged code automatically.

    When you do a declaration you have to make sure you are using Unicode though.

    So a declaration will look like this: (C#)

    [DllImport("dmscli.dll", CharSet = CharSet.Unicode, EntryPoint= "aaApi_EncryptLoginPassword")]
    [return: MarshalAs(UnmanagedType.LPWStr)]
    public static extern string EncryptLoginPassword(string userPassword);

    and VB:

        <DllImport("dmscli.dll", CharSet:=CharSet.Unicode, EntryPoint:="aaApi_EncryptLoginPassword")> _
        Public Shared Function EncryptLoginPassword(ByVal userPassword As String) As <MarshalAs(UnmanagedType.LPWStr)> String
            'This is an empty function template, do not add code here, the call will be directed to the external dll.
        End Function

    OR

        Declare Auto Function EncryptPassword Lib "dmscli.dll" Alias "aaApi_EncryptLoginPassword" (<MarshalAs(UnmanagedType.LPWStr)> ByVal password As String) As <MarshalAs(UnmanagedType.LPWStr)> String

    Please note that the <MarshallAs> attributes are not really required for the Declare Auto Function so it can just be declared as:
     Declare Auto Function EncryptPassword Lib "dmscli.dll" Alias "aaApi_EncryptLoginPassword" (ByVal password As String) As String, and it should work fine.