on 07-20-2004 6:12 PM
I have declared The GetInstallPath function in C# like this:
[DllImport("SBOAddonReg.dll")]
public static extern long GetInstallPath(string installDataFile, string outStr, long pathLength);
I call the declared function like this:
sapInstallPath = sapInstallPath.PadLeft(1024, ' ');
installDataFile = Application.StartupPath + @"\SBOAddOnRegData.sld";
GetInstallPath(installDataFile, sapInstallPath, sapInstallPath.Length);
But the sapInstallPath is always blank. Is there something incorrect in my declaration? Or my call?
To use GetInstallPath you need to call the function like this:
[DllImport(@"C:\Program Files\SAP Manage\SAP Business One SDK\UI API\Tools\SBOAddonReg.dll", EntryPoint="GetInstallPath", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl)]
private static extern long GetInstallPath([MarshalAs(UnmanagedType.LPArray)] byte[] installDataFile,
[MarshalAs(UnmanagedType.LPArray)] byte[] outStr,
[MarshalAs(UnmanagedType.LPArray)]Int32[] lLen );
In C#, dlls written in C++ are viewed as "unmanaged" code and you need to marshall the data if you require return values from any methods.
To get the installation path, use the routine below:
byte[] bPath = new byte[500];
Int32[] lLen = new Int32[1];
lLen[0] = 20;
//Get the sPath where to install the addon exe
string InstallStrFile = RegDir + @"\SBOAddOnRegData.sld";
byte[] InstallFile = new byte[InstallStrFile.Length];
InstallFile = System.Text.UTF8Encoding.ASCII.GetBytes(InstallStrFile);
long Tmp = GetInstallPath(InstallFile, bPath, lLen);
//convert the byte array back into a useable string - this returns a string with
//the same length as the array. The end of the string contains \0\0\0 characters
string InstallPath = System.Text.Encoding.ASCII.GetString(bPath);
//get the actual size of the string
int i = 0;
for (i = 0; i < bPath.Length; i++)
{
if (bPath<i> == 0)
break;
}
//set the string to a usaable form - this removes all the \0\0 at the end of the string
InstallPath = InstallPath.Substring(0, i);
The routine is rather long winded but it does work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One reason could be that Microsoft has changed the definition of long in .Net. A variable of type long in VB6 is equivalent to type integer in .Net (no matter what languages you use)
Try using integer instead of long. Passing a long means passing a value which probably is too large in size.
[DllImport("SBOAddonReg.dll")]
public static extern integer GetInstallPath(string installDataFile, string outStr, integer pathLength);
HTH Lutz Morrien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
12 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.