Hi Rick,
Actually, that C++ dll works fine from VFP. But when I tried to call it from C# using DllImport attribute as I shown it crashed C# application. I already determined that there is some strange corruption in that C++ dll, because the older version of it worked.
>You can't call a DLL function that returns a string because there's no way for FoxPro - at least not without an FLL in between - to capture the pointer that the function returns. CDecl calling convention generally doesn't work - you can only really call DLLs with WINAPI calling convention which has all APIs pretty much returning numeric values and any 'real' return values returned in passed in buffers.
>
>Your best bet is to wrap the function in a .NET DLL and call it with wwDotnetBridge or plain COM interop.
>
>+++ Rick ---
>
>>Hi everybody,
>>
>>This is how the function is declared in C# (see VFP declaration in a comment - it works fine from VFP):
>>
>>
>> //declare string Invoke1 in (addbs(justpath(.cProgramPath)) + "ww_local.dll") as ww_localInvoke string cInvokeString
>>
>> [DllImport(@"C:\Program Files (x86)\Siriusware\Pool\ww_local.dll",
>> ExactSpelling = false,
>> CallingConvention = CallingConvention.Cdecl,
>> CharSet = CharSet.Auto)]
>> static extern String Invoke1([MarshalAs(UnmanagedType.LPTStr)] String str);
>>
>>And then in the C# code I try to do
>>
>>
>> translate = Invoke1(invoke);
>>
>>and then the C# test stops and I see a dmp file generated.
>>
>>If I try to open that file in VS 2015 and debug in mixed mode I get
>>
>>Unhandled exception at 0x777F9D71 (ntdll.dll) in vstest.executionengine.x86.exe.13284.dmp: 0xC0000374: A heap has been corrupted (parameters: 0x7782D8D0).
>>
>>What can I do to figure out what may be a problem and why it works from VFP but not C#?
>>
>>Thanks a lot in advance.
If it's not broken, fix it until it is.
My Blog