TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
pat 0
NA
6
0
PInvoke & DllImport
Sep 18 2003 1:16 PM
Hey All, I'm trying to access a non COM compliant dll written by MS Great Plains called crypto.dll here's its methods:
VOID WINAPI CryptoInit(CSTR_PTR regkeystring) This must be called before using any other functions !! It must be passed a 1 character "X" c-string ("X") - this is the current "Registration key string" for this DLL - all functions are inoperable until they are unlocked with this key string VOID WINAPI TableColumnEncrypt(CSTR_PTR datastring, LONG method ) VOID WINAPI TableColumnDecrypt(CSTR_PTR datastring, LONG method ) For these 2, the c-string format datastring is converted in-place, and the only method currently supported is method=0 - This may change in the future if the encryption algorithm changes. 'INT WINAPI EncodeSQLPass(LPSTR input_string, LPSTR output_string ) 'INT WINAPI DecodeSQLPass(LPSTR input_string, LPSTR output_string )
I wrote a class in my asp.net(c#) app to access it as follows:
public class crypto { [DllImport("crypto.dll")] public static extern void CryptoInit(string regkeystring); [DllImport("crypto.dll")] public static extern long TableColumnEncrypt([MarshalAs(UnmanagedType.LPStr)]string datastring, long method); [DllImport("crypto.dll")] public static extern long TableColumnDecrypt([MarshalAs(UnmanagedType.LPStr)]string datastring, long method); [DllImport("crypto.dll")] public static extern string EncodeSQLPass([MarshalAs(UnmanagedType.LPStr)]string input_string); [DllImport("crypto.dll")] public static extern string DecodeSQLPass([MarshalAs(UnmanagedType.LPStr)]string input_string); }
The documentation has a sample VB 6 file to use it, the core is the following:
' used for "encrypted columns of dex tables" use method = 0 'VOID WINAPI TableColumnEncrypt(LPSTR datastring, LONG method ) Declare Sub TableColumnEncrypt Lib "crypto.dll" (ByVal datastring As String, ByVal method As Long) 'VOID WINAPI TableColumnDecrypt(LPSTR datastring, LONG method ) Declare Sub TableColumnDecrypt Lib "crypto.dll" (ByVal datastring As String, ByVal method As Long) ' used for passing data to DPS - must use correct key passed in the method param. 'VOID WINAPI SensitiveDataEncrypt(LPSTR in_string,LONG key ) Declare Sub SensitiveDataEncrypt Lib "crypto.dll" (ByVal datastring As String, ByVal method As Long) 'VOID WINAPI SensitiveDataEncrypt(LPSTR in_string,LONG key ) Declare Sub SensitiveDataDecrypt Lib "crypto.dll" (ByVal datastring As String, ByVal method As Long) ' used for encrypting SQL password in dex table 'INT WINAPI EncodeSQLPass(LPSTR input_string, LPSTR output_string ) Declare Sub EncodeSQLPass Lib "crypto.dll" (ByVal input_string As String, ByVal output_string As String) 'INT WINAPI DecodeSQLPass(LPSTR input_string, LPSTR output_string ) Declare Sub DecodeSQLPass Lib "crypto.dll" (ByVal input_string As String, ByVal output_string As String) ' must be called first with the correct regkeystring to use this dll Declare Sub CryptoInit Lib "crypto.dll" (ByVal regkeystring As String) I think I basically need to convert the above into C# and I am just having problems with it. My first time using DllImport. Thanks for your help.
Reply
Answers (
1
)
Writing to a process
passing parameters from c# to vb com+ .dll