Hi
I hope someone can help me solve this riddle with c#.
I'm trying to write a webservice that calls a PB dll (v8.04).
My dll (besides a clean LibMain) is this:
I'm trying to find out how to pass a string the proper way.
In my c# webservice, I have the following declarations and webmethod:
What I get back is always 255, even I just enter a sVar of just 4 characters. Extracting on Chr$(0) doesn't help either.
I've tried playing with leaving the SizeConst in the webdeclaration and AnsiBStr and I just cannot figure out what I'm doing wrong here.
What I want to archieve in the end is how to pass a pointer (of a string or a struct):
Additional function in PB
Additional stuff in the webservice:
This doesn't work at all.. At least I cannot get it to work.
Hope someone can give me tip on where to go with this.
Many regards
Jeroen Brouwers
I hope someone can help me solve this riddle with c#.
I'm trying to write a webservice that calls a PB dll (v8.04).
My dll (besides a clean LibMain) is this:
Code:
FUNCTION Test1 ALIAS "TEST1" ( ProjectID AS LONG, sVar AS STRING ) EXPORT AS LONG FUNCTION = LEN( sVar ) END FUNCTION FUNCTION Test2 ALIAS "TEST2" ( ProjectID AS LONG, sVar AS STRING * 255 ) EXPORT AS LONG FUNCTION = LEN(TRIM$( sVar )) END FUNCTION
In my c# webservice, I have the following declarations and webmethod:
Code:
[DllImport("test.dll", EntryPoint = "TEST1", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] private static extern int test1( int projectid, [MarshalAs(UnmanagedType.AnsiBStr,SizeConst=255)] string sVar ); [DllImport("test.dll", EntryPoint = "TEST2", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] private static extern int test2( int projectid, [MarshalAs(UnmanagedType.AnsiBStr,SizeConst=255)] string sVar ); [WebMethod] public int RunTest1(string sVar) { try { return test1(1, sVar); } catch (Exception ex) { return -1; } } [WebMethod] public int RunTest2(string sVar) { try { return test2(1, sVar); } catch (Exception ex) { return -1; } }
I've tried playing with leaving the SizeConst in the webdeclaration and AnsiBStr and I just cannot figure out what I'm doing wrong here.
What I want to archieve in the end is how to pass a pointer (of a string or a struct):
Additional function in PB
Code:
FUNCTION Test3 ALIAS "TEST3" ( ProjectID AS LONG, BYVAL sVar AS STRING PTR ) EXPORT AS LONG FUNCTION = LEN(TRIM$( @sVar )) END FUNCTION
Code:
[DllImport("test.dll", EntryPoint = "TEST3", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)] private static extern int test3( IntPtr sVar ); public int RunTest3(string sQuestion) { try { IntPtr s = Marshal.StringToHGlobalAnsi(sQuestion); int result = test3(1, ref s); Marshal.FreeHGlobal(s); return result; } catch (Exception ex) { return -1; } }
Hope someone can give me tip on where to go with this.
Many regards
Jeroen Brouwers
Comment