Hi,

thanks for all the help I got so far ... NIM is a treasure :)

Ok, now I am stuck at a CONVERSION from a WideCString string to a string in 
NIM. I know I have to use cast to link to the address of the CString, however 
... I get errors ...

Here is my code with comments:
    
    
    import winlean, nimpy
    
    proc    findFirstFile(a: string, b: var WIN32_FIND_DATA): Handle =
            result = findFirstFileW(newWideCString(a), b)
    
    proc    findNextFileW*(hFindFile: Handle, lpFindFileData: var 
WIN32_FIND_DATA): int32
            {.stdcall, dynlib: "kernel32", importc: "FindNextFileW", 
sideEffect.}
    
    template    getFilename(f: untyped): untyped =
                $cast[WideCString](addr(f.cAlternateFileName[0]))
    
    proc test*(file: string): WIN32_FIND_DATA {.exportpy.} =
            
            var FileInfo: WIN32_FIND_DATA
            var Handle = findFirstFile(file, FileInfo)
            
            #[
            tried THIS:
                    
                    echo FileInfo.cAlternateFileName
            
            ==> ERROR MSG
                Error: type mismatch: got <array[0..259, Utf16Char]>
                but expected one of:
                proc echo(x: varargs[typed, `$`])
                    first type mismatch at position: 1
                    required type for x: varargs[typed]
                    but expression 'FileInfo.cAlternateFileName' is of type: 
array[0..259, Utf16Char]
                
                expression: echo FileInfo.cAlternateFileName
            
            
            
            tried THIS:
                    
                    echo getFilename(FileInfo)
            
            ==> ERROR MSG
                Error: type mismatch: got <Utf16Char>
                but expected one of:
                proc unknownTypeCompileError()
                  first type mismatch at position: 1
                  extra argument given
                
                expression: unknownTypeCompileError(v)
            
            ]#
            
            result = FileInfo
    
    
    Run

Reply via email to