static import .dll - works but doesn't work well? lazarus / 35-Windows CE ---------------------------------------------------------------------- mmikac · 2010-11-16 10:23 I just got .dll from bluetooth printer supplier (Citizen). Source for C#,VB,MFC is included, WinCE exe too... So I checked and it seems to work quite well - opening port, printing, closing port, detecting printer not alive etc. However, when I try to use it with Lazarus (static .dll) e.g. function OpenPort(PortName:WideString;BaudRate:longint):longint;StdCal l;External'CITIZEN2.dll' ; function ClosePort():longint;StdCall;External'CITIZEN2.dll'; (in C#, their code looks like: [DllImport(CITIZEN2DIR, SetLastError = true, EntryPoint = "OpenPort")]         public static extern Int32 OpenPort(string PortName, Int32 BaudRate); [DllImport(CITIZEN2DIR, SetLastError = true, EntryPoint = "ClosePort")]         public static extern Int32 ClosePort();       It compiles well, it connects with .dll, but I am not so sure that it works fine - OpenPort returns some unknow values etc. In other words it is quite useless... Is there a way to somehow check this .dll and see whether function declarations in my .pas file are maybe wrong? ---------------------------------------------------------------------- Laksen · 2010-11-16 11:36 Try using pchar instead of widestring ---------------------------------------------------------------------- mmikac · 2010-11-16 11:49 already tried, but I get the same result... it's like being blind. what ever I send to the function I always get the same, wrong, result if anyone wants to try, I will upload .dll file (if possible here on forum) ---------------------------------------------------------------------- felipemdc · 2010-11-16 11:52 Try using PWideChar. Widestring is a managed Pascal type, it cannot possibly be right. ---------------------------------------------------------------------- mmikac · 2010-11-16 12:18 Tried... PChar, PWideChar, PWideString, PUTF8String.. always get return code 104, which is not documented at all (only FAIL and SUCCESS are - -1,0) Also tried integer and longint as result and portspeed parameters... Testing on emulator + testing on real device with bluetooth printer on/off... all cases - result=104 ---------------------------------------------------------------------- felipemdc · 2010-11-16 12:23 your posted code is too small. It should also include how the functions are used and how the string is initialized in both pascal and another language. ---------------------------------------------------------------------- ivan17 · 2010-11-16 12:42 try to post the declarations (preferably c/c++) from that source code you mentioned. that "string" means either PAnsiChar or PWideChar. make sure you allocate enough characters if the function changes the string.  oh, and try cdecl instead of stdcall (not likely but you might as well give it a shot). ---------------------------------------------------------------------- mmikac · 2010-11-16 12:51 Felipe got me thinking... So, I checked - I call the function from Pascal casting first parameter to PWideChar But! I now noticed (I completely didn't think about it before) that the value that is being cast is of type string. I changed to WideString and it seems to matter - I didn't check it on device yet, but I finally get some other value than 104 Give me few minutes to check, I will get back with results... ---------------------------------------------------------------------- mmikac · 2010-11-16 13:03 Communication established... Now "just" have to redesign already implemented printing features