Спасибо someOne за ответ.
Вот еще вариант на VS (рабочий)
X++:
using System;
using System.Runtime.InteropServices;
namespace NetShare
{
class Program
{
[DllImport("Netapi32.dll", SetLastError = true)]
static extern int NetApiBufferFree(IntPtr Buffer);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 4)]
struct FILE_INFO_3
{
public int fi3_id;
public int fi3_permission;
public int fi3_num_locks;
public string fi3_pathname;
public string fi3_username;
}
[DllImport("netapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern int NetFileEnum(
string servername,
string basepath,
string username,
int level,
ref IntPtr bufptr,
int prefmaxlen,
out int entriesread,
out int totalentries,
IntPtr resume_handle
);
[DllImport("netapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
static extern int NetFileGetInfo(
string servername,
int fileid,
int level,
ref IntPtr bufptr
);
static void Main(string[] args)
{
const int MAX_PREFERRED_LENGTH = -1;
int dwReadEntries;
int dwTotalEntries;
IntPtr pBuffer = System.IntPtr.Zero;
FILE_INFO_3 pCurrent = new FILE_INFO_3();
int dwStatus = NetFileEnum("<mashineName>", "<fileName>", null, 3, ref pBuffer, MAX_PREFERRED_LENGTH, out dwReadEntries, out dwTotalEntries, IntPtr.Zero);
if (dwStatus == 0)
{
for (int dwIndex = 0; dwIndex < dwReadEntries; dwIndex++)
{
IntPtr iPtr = new IntPtr(pBuffer.ToInt32() + (dwIndex * Marshal.SizeOf(pCurrent)));
pCurrent = (FILE_INFO_3)Marshal.PtrToStructure(iPtr, typeof(FILE_INFO_3));
Console.WriteLine("dwIndex={0}", dwIndex);
Console.WriteLine(" id={0}", pCurrent.fi3_id);
Console.WriteLine(" num_locks={0}", pCurrent.fi3_num_locks);
Console.WriteLine(" pathname={0}", pCurrent.fi3_pathname);
Console.WriteLine(" permission={0}", pCurrent.fi3_permission);
Console.WriteLine(" username={0}", pCurrent.fi3_username);
}
NetApiBufferFree(pBuffer);
}
Console.Read();
}
}
}
Пытаюсь перенести на аксу
X++:
static void Job117(Args _args)
{
DLL netApi32 = New Dll("netapi32.dll");
DLLFunction NetFileEnum = new DllFunction(netApi32, "NetFileEnum");
int dwStatus, dwReadEntries, dwTotalEntries, res ;
Binary struct;
int MAX_PREFERRED_LENGTH = -1;
System.IntPtr pBuffer = new System.IntPtr(0);
;
NetFileEnum.arg(ExtTypes::String,
ExtTypes::String,
ExtTypes::String,
ExtTypes::DWord,
ExtTypes::void,
ExtTypes::DWord,
ExtTypes::DWord,
ExtTypes::DWord,
ExtTypes::Pointer);
dwStatus = NetFileEnum.call("<mashineName>",
"",
"",
3,
pBuffer,
MAX_PREFERRED_LENGTH,
dwReadEntries,
dwTotalEntries,
pBuffer);
if(dwStatus == 0)
{
info("");
}
}
Не проходит пишет ошибку
Значение регистра ESP не было сохранено при вызове функции "NetFileEnum" в библиотеке DLL "netapi32.dll". Причиной может являться вызов функции DLL, которая объявлена с неверным числом аргументов.
Что я делаю не так?