Try using Winapi :: findFirstFile running on the server

I have a problem running Winapi::findFirstFileon the server. I already tried to copy the method on the WinapiServer class and changed some lines, for example:

server static container findFirstFile(str filename)
{
    InteropPermission interopPerm;
    Binary data;
    DLL _winApiDLL;
    DLLFunction _findFirstFile;
    ;

    interopPerm = new InteropPermission(InteropKind::DllInterop);
    interopPerm.assert();

    data = new Binary(592); // size of WIN32_FIND_DATA when sizeof(TCHAR)==2
    _winApiDLL = new DLL(#KernelDLL);
    _findFirstFile = new DLLFunction(_winApiDLL, 'FindFirstFileW');

    _findFirstFile.returns(ExtTypes::DWord);

    _findFirstFile.arg(ExtTypes::WString,ExtTypes::Pointer);

    return [_findFirstFile.call(filename, data),data.wString(#offset44)];
}

But now I have another error. The function "FindFirstFileW" in the DLL "KERNEL32" throws an exception.

This is because I am executing the method on the x64 server. Anyone who decided to solve this problem?

+5
source share
3 answers

Here is an example of code that worked for me both on the client side and on the server side. It uses .NET namespaces to retrieve a list of files in a given folder path for a given template.

, FindFirstFile .

X ++

static container findMatchingFiles(
        str _folderPath
    ,   str _filePattern   = '*.*')
{
    System.IO.DirectoryInfo     directory;
    System.IO.FileInfo[]        files;
    System.IO.FileInfo          file;
    InteropPermission           permission;

    str         fileName;
    counter     filesCount;
    counter     loop;
    container   mathchingFiles;
    ;

    permission  = new InteropPermission(InteropKind::ClrInterop);
    permission.assert();

    directory   = new System.IO.DirectoryInfo(_folderPath);
    files       = directory.GetFiles(_filePattern);
    filesCount  = files.get_Length();

    for (loop = 0; loop < filesCount; loop++)
    {
        file            = files.GetValue(loop);
        fileName        = file.get_FullName();
        mathchingFiles  = conins(mathchingFiles, conlen(mathchingFiles) + 1, fileName);
    }

    CodeAccessPermission::revertAssert();

    return mathchingFiles;
}

, C:\temp\Files\

List of files

Tutorial_WinApiServer. fetchFiles .

static void fetchFiles(Args _args)
{
    container   files;
    counter     loop;
    str         fileName;
    ;

    files = Tutorial_WinApiServer::findMatchingFiles(@'C:\temp\Files', '*.txt');

    for (loop = 1; loop <= conlen(files); loop++)
    {
        fileName = conpeek(files, loop);
        info(fileName);
    }
}

.

Job Output 1

F *. * .

Job output 2

, .

+6

, .NET- System.String str. :

directory   = new System.IO.DirectoryInfo(_folderPath);

CIL :

Unable to create entry in compiler information (TmpCompilerOutput). Path: \ Classes \\, Warning: Proxy server not found. The FileIOPermission type is found on the stack. This code is in the class :, Method :.

My solution is to assign _folderPath to System.String.

0
source

All Articles