As the title suggests, I'm trying to write some C# code to interop with a C DLL (It's a Windows device driver, basically). The error code function signature in C is:
UINT DLLErrorMsg( DWORD errorCode, char * pBuf, UINT nSize );
nSize is the size of pBuf. If nSize can fit the error message, it is copied into pBuf and 0 returned, othe...
Hi,
i need help about custom marshaling..i have a native DLL..the parameters of the some DLL functions is defined with unsigned char*
for example;
typedef short apiStatus;
apiStatus __declspec(dllexport) __stdcall DrfGetFirmwareVersion (HANDLE hCom, unsigned char *major,unsigned char *minor, unsigned char ReaderAddr = 0xff);
t...
I am wondering why the .NET framework does not provide any managed methods for working with USB drivers. From everything I have read you still have to call into Windows API's and use marshalling and PInvoke and all that crap that none of us .NET programmers want to have to do. Why does .NET provide methods for communicating with serial ...
I've got an unmanaged DLL that is writing log messages to standard output. I'm calling this DLL with P-invokes from a WPF app and I need to get the standard output stream log. I've tried Console.SetOut, but that only seems to capture information written using Console.Write, etc.
Anyone have any ideas? I've found similar questions asked ...
Suppose you're calling a Win32 function that will fill in your byte array. You create an array of size 32, empty. Then pass it in to the Win32 function to be filled int, and use it later in your managed code. Does there exist the chance that the byte array might be moved or overwritten in between the time it was allocated and it is fille...
Hello, I am completely new to C#, and need help converting a C++ structure to C#. The C++ structure is given as:
#define QUE_ADDR_BUF_LENGTH 50
#define QUE_POST_BUF_LENGTH 11
typedef struct
{
const WCHAR *streetAddress;
const WCHAR *city;
const WCHAR *state;
const WCHAR *country;
const WCHAR *postalCode;
} QueS...
I'm trying to get information about a Windows Mobile device from a desktop application (written in C#).
I searched the MSDN and found that the function I need is in rapi.dll:
VOID CeGetSystemInfo (LPSYSTEM_INFO lpSystemInfo);
The parameter is a pointer to a struct which is deffined like this:
typedef struct _SYSTEM_INFO {
union {...
I'm writing a wrapper class in C# for a USB device (using P/Invoke to communicate with it). The device needs to be sent an open message before use, and a close method when it's done with. In my constructor I want to try to open the device and return null if that call fails for whatever reason. I'll also write a Dispose() which calls the ...
I have a native C++ DLL using DirectX, that I want to be able to use through C# to be able to create content creation tools.
Adding COM would require quite an effort it seems.
Can P/Invoke be used to maintain classes using polymorphism, or would it require me to wrap most of the code to facilitate use of P/Invoke?
It there a better sol...
I am trying to write the C# equivalent to the following:
typedef struct BATT_ID
{
UINT8 nBattID[8];
} BATT_ID, *PBATT_ID;
HANDLE g_hDevice;
// Connect to the driver
g_hDevice = CreateFile(L"BAT1:", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
void GetB...
I'd like to use a specific ICO file as my icon with a WinForms application. Since I want to be able to specify a small icon (16x16) for the title bar and a normal icon (32x32) when Alt-Tabbing, I cannot use the Form.Icon property which accepts a single System.Drawing.Icon object, which forces me to use either the low res icon, or the nor...
I am trying to call the PrintDlgW Win32 API from C# via P/Invoke. With the help of P/Invoke Interop Assistant 1.0 from Microsoft, I am able to declare necessary data structures and import functions from DLL. But how to use the HDC or HWND in C#? Thanks in advance.
...
Hi,guys! I am calling "PrintDlg" Win32 API via P/Invoke. Strange enough, if I use Visual Studio debug mode (press F5) to run my application, the last error is 122, which means "The data area passed to a system call is too small" , but if i ran it with Ctrl+F5, the last error is 0 and the message is "The operation completed successfully"...
Hi, quick question. I want to find out if a DLL is present in the system where my application is executing.
Is this possible in C#? (in a way that would work on ALL Windows OS?)
For DLL i mean a non-.NET classic dll (a Win32 dll)
(Basically I want to make a check cause I'm using a DLL that may or may not be present on the user system,...
I am creating a label control which can be used on Aero Glass and I want the text to glow "the Vista way". There is a WinAPI function called 'DrawThemeTextEx' but I don't know how to use it and searching didn't give many results.
I found this message but it doesn't tell you much : http://www.codeproject.com/Messages/3273238/Text-on-Aer...
I'm trying to use this code to draw a Bitmap directly onto a PictureBox:
Bitmap bmp = (Bitmap)Bitmap.FromFile(@"C:\Users\Ken\Desktop\Load2.bmp");
Graphics grDest = Graphics.FromHwnd(pictureBox1.Handle);
Graphics grSrc = Graphics.FromImage(bmp);
IntPtr hdcDest = grDest.GetHdc();
IntPtr hdcSrc = grSrc.GetHdc();
BitBlt(hdcDest, 0, 0, pictu...
I have written a C DLL and some C# code to test including this DLL and executing functions from it. I am not too familiar with this process, and am receiving a PInvokeStackImbalance exception whenever my DLL function is called from the C# source code. The code is as follows (I have commented most code out to isolate this problem):
C# In...
This is what I have so far:
Dim bProcess = Process.GetProcessesByName("By").FirstOrDefault
If bProcess IsNot Nothing Then
SwitchToThisWindow(bProcess.MainWindowHandle, True)
Else
Process.Start("C:\Program Files\B\B.exe")
End If
It has two problems.
Some people have told me that SwitchToThisWindow is d...
I have a VB 6 MDI application. It responds to the depricated SwitchToThisWindow function, but not the ShowWindow and SetActiveWindow functions. I know ShowWindow and SetActiveWindow are declared correctly because I can use them with any other application.
EDIT: My goal isn't to use these functions, it is simple to switch the focus from ...
This code works to output a piano tone for 2 seconds using winmm.dll via platform invocation services, it seems to work fine on XP but waveoutopen fails in windows 7 rc
updated based on feedback from John Knoeller
Imports System.Runtime.InteropServices
Public Class AudioStream
<StructLayout(LayoutKind.Sequential)> _
Private Structure ...