J
Jim shedden
Hi,
I've really flailed at this today, and read many posts and MSDN help
areas. I would really appreciate a sanity check.
The DLL is for OziExplorer API, the function declaration from the
documentation is:
function oziGetExePath(var Path
ansichar;
var DataLenth:integer):integer;stdcall;
I believe that PAnsiChar is a Delphi type for "pointer to Ansi Char"
and can be used similar to LPSTR to point at null terminated strings.
In general the API states return values as -1 for timeout, 0 for
completion, or other numbers as indicated by the specific funtion.
This function should return the path to the EXE file, so I expect it
should return only 0 or -1.
In C# I write the following:
________
StringBuilder sb = new StringBuilder(512);
[DllImport("OziAPI.dll", CharSet = CharSet.Ansi, CallingConvention =
CallingConvention.StdCall)]
static extern int oziGetExePath(ref StringBuilder s, ref int length);
public string getOziExePath()
{
int size = 0;
int ret;
ret=oziGetExePath(ref sb, ref size);
//if (ret != 0)
// throw new Exception("Could not get Ozi exe Path");
return (sb.ToString());
}
___________
1. While the return value is correct, the "ret" value is 1, so my API
error trap will always throw an exception. I'm a bit leery about
ignoring return values.
2. In examples I do not see the StringBuilder passed by reference. I
do not get the correct result if I do not pass by reference. I also
tried defining the path parameter as String. It also required a "ref"
and the behaviour is identical to using StringBuilder.
3. I think that the unmanaged code allocates a buffer, and I don't
want the CLR to try and release it. The API provides a "close"
function to free up storage, as it reuses it internally. I tried some
tricks with "IntPtr" and "Marshal.PtrToStringAuto()" that did not seem
to work either.
I would be happy to learn more from anyone in the group! Thanks in
advance for any help.
Regards,
Jim
I've really flailed at this today, and read many posts and MSDN help
areas. I would really appreciate a sanity check.
The DLL is for OziExplorer API, the function declaration from the
documentation is:
function oziGetExePath(var Path

var DataLenth:integer):integer;stdcall;
I believe that PAnsiChar is a Delphi type for "pointer to Ansi Char"
and can be used similar to LPSTR to point at null terminated strings.
In general the API states return values as -1 for timeout, 0 for
completion, or other numbers as indicated by the specific funtion.
This function should return the path to the EXE file, so I expect it
should return only 0 or -1.
In C# I write the following:
________
StringBuilder sb = new StringBuilder(512);
[DllImport("OziAPI.dll", CharSet = CharSet.Ansi, CallingConvention =
CallingConvention.StdCall)]
static extern int oziGetExePath(ref StringBuilder s, ref int length);
public string getOziExePath()
{
int size = 0;
int ret;
ret=oziGetExePath(ref sb, ref size);
//if (ret != 0)
// throw new Exception("Could not get Ozi exe Path");
return (sb.ToString());
}
___________
1. While the return value is correct, the "ret" value is 1, so my API
error trap will always throw an exception. I'm a bit leery about
ignoring return values.
2. In examples I do not see the StringBuilder passed by reference. I
do not get the correct result if I do not pass by reference. I also
tried defining the path parameter as String. It also required a "ref"
and the behaviour is identical to using StringBuilder.
3. I think that the unmanaged code allocates a buffer, and I don't
want the CLR to try and release it. The API provides a "close"
function to free up storage, as it reuses it internally. I tried some
tricks with "IntPtr" and "Marshal.PtrToStringAuto()" that did not seem
to work either.
I would be happy to learn more from anyone in the group! Thanks in
advance for any help.
Regards,
Jim