dllimport

Load C library (gsdll32.dll) from Metro Style App c#

China☆狼群 提交于 2019-12-05 12:12:34
I want to use gsdll32.dll from Metro Style App c#. I load dll as follow: [DllImport("gsdll32.dll", EntryPoint = "gsapi_delete_instance")] private static extern void gsapi_delete_instance(IntPtr instance); [DllImport("gsdll32.dll", EntryPoint = "gsapi_revision")] private static extern int gsapi_revision(ref GS_Revision pGSRevisionInfo, int intLen); [DllImport("gsdll32.dll", EntryPoint = "gsapi_set_stdio")] private static extern int gsapi_set_stdio(IntPtr lngGSInstance, StdioCallBack gsdll_stdin, StdioCallBack gsdll_stdout, StdioCallBack gsdll_stderr); But when I try to load dll not found

How to call from a C# applicaiton a C++ function taking a pointer to void?

只愿长相守 提交于 2019-12-05 09:32:59
I have a dynamic library ( .dll ) written in C++ exporting a function I'd like to use in my C# applicaiton: int SendText(void* pControl, char* sText); How can I, given it takes a pointer to void? Nitin Sawant for void* you can just use IntPtr , strings will work with the MarshalAs attribute: [DllImport("MyDll.dll", CharSet = CharSet.Ansi)] public static extern int SendText(IntPtr pControl, [MarshalAs(UnmanagedType.LPStr)] string sText); 来源: https://stackoverflow.com/questions/10630419/how-to-call-from-a-c-sharp-applicaiton-a-c-function-taking-a-pointer-to-void

Which DLL is [DllImport] loading?

不羁岁月 提交于 2019-12-05 09:02:32
I'm using the [DllImport] attribute to import a native DLL into my application but the DLL it's loading isn't in the local bin folder. It's being loaded from elsewhere on the system, but I can't work out where. It works on my dev machine but not on a clean one. I've enabled Fusion logging and that only shows me managed assemblies. I've dumped the process using Sysinternals Process Explorer and that's telling me it's in C:\Windows\System32 but I can't see the file there in Windows Explorer. It might be worth noting that I'm running 64 bit Windows 7 but the DLL only supports x86 so I've had to

Using Delphi DLL in C#

前提是你 提交于 2019-12-05 08:21:58
I have a third party "mystery dll" written with Delphi(unknown version), working example in delphi (past 2009), dire need to use said dll in my C# code, and almost no relevant knowledge on how to do it. Here is Delpi example in using this dll: type TD_Query = function(host: WideString; port : Word;pud,query : WideString):WideString; stdcall; procedure TForm11.Button6Click(Sender: TObject); var Handle : LongWord; D_Query : TD_Query; sss : WideString; begin Handle := LoadLibrary('kobrasdk.dll'); sss:=''; if Handle <> 0 then begin @D_Query := GetProcAddress(Handle, 'D_Query'); sss:=D_Query('host'

How to compile a C DLL for 64 bit with Visual Studio 2010?

对着背影说爱祢 提交于 2019-12-05 08:01:30
I have a DLL written in C in source code. This is the code for the General Polygon Clipper (in case you are interested). I'm using it in a C# project via the C# wrapper provided on the homepage. This comes with a precompiled DLL. Since switching to a 64bit Development machine with Visual Studio 2010 and Windows 7 64 bit, the application won't run anymore. This is the error I get: An attempt was made to load a program with an incorrect format. This is because of DLLImport ing the 32bit gpc.dll , as I have gathered from stuff found on the web. I assume this will all go away if I recompile the

How to call a C++ function with a struct pointer parameter from C#?

寵の児 提交于 2019-12-05 02:09:56
Okay one more function that it's not yet working. I am basically calling some C++ functions from C# by using P/Invoke. The problematic function does query a show laser device for some device related information, such as minimal and maximal scan rates and maximal points per second. The problematic function is: int GetDeviceInfo(DWORD deviceIndex, DeviceInfo* pDeviceInfo); Here's the C++ header file that I was given. That's a link to the very brief C++ SDK description . I don't have the sources to rebuild the DLL file and I also don't have the *.pdb file (the manufacturer can not supply it):

Explanation about high-resolution performance counter and its existence related to .NET Stopwatch?

丶灬走出姿态 提交于 2019-12-05 01:24:09
Inside the static Stopwatch constructor we can see the following code, that basicly checks whether a high-resolution performance counter exists. static Stopwatch() { if (!SafeNativeMethods.QueryPerformanceFrequency(out Frequency)) { IsHighResolution = false; Frequency = 0x989680L; tickFrequency = 1.0; } else { IsHighResolution = true; tickFrequency = 10000000.0; tickFrequency /= (double) Frequency; } } On MSDN it says about QueryPerformanceFrequency : Retrieves the frequency of the high-resolution performance counter, if one exists It's pretty unclear, however, when exactly does it exist? I

C++ from C#: C++ function (in a DLL) returning false, but C# thinks it's true!

和自甴很熟 提交于 2019-12-05 01:12:42
I'm writing a little C# app that calls a few functions in a C++ API. I have the C++ code building into a DLL, and the C# code calls the API using DllImport. (I am using a .DEF file for the C++ DLL so I don't need extern "C".) So far the API has one function, which currently does absolutely nothing: bool Foo() { return false; } In C#, I have the following: public class FooAPI { [DllImport("Foo.dll")] public static extern bool Foo(); } ... bool b = FooAPI.Foo(); if (!b) { // Throw an exception } My problem is that, for some reason, b is always evaluating to TRUE . I have a breakpoint on if (!b)

how to track dlls being loaded into a process?

荒凉一梦 提交于 2019-12-04 21:57:10
I am looking for a tool to trace the dlls being loaded into a process on windows. The app i have is loading managed and unmanaged dlls, but not sure if the managed ones are loading the unmaanged ones. Process Explorer and File Explorer doesn't seem to help much. Any thoughts?? thanks!! Procmon is the best tool I know of, though its level of detail can be overwhelming. As of version 2.0, Dependency Walker can do dynamic application profiling . This allows you to see what modules a running application is loading, as opposed to just seeing what is in the static import tables. 来源: https:/

Passing pointers from unmanaged code

此生再无相见时 提交于 2019-12-04 21:54:58
问题 I have a C# project that imports a C dll, the dll has this function: int primary_read_serial(int handle, int *return_code, int *serial, int length); I want to get access to the serial parameter. I've actually got it to return one character of the serial parameter, but I'm not really sure what I'm doing and would like to understand what is going, and of course get it working. So, I'm very sure that the dll is being accessed, other functions without pointers work fine. How do I handle pointers?