473,320 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

C Api interface

Hi,

got this c api interface:

#ifndef _USBCDDLL_HPP
#define _USBCDDLL_HPP
#define DEVICE_COMMANDOK 0
#define DEVICE_IDERROR 1
#define DEVICE_BUSY 2
#define DEVICE_UNKNOWERROR 3

extern "C"
{
typedef void (CALLBACK* CDDeviceChangePROC )(int);

WINUSERAPI VOID WINAPI InitUSBCDLibrary();
WINUSERAPI VOID WINAPI CloseUSBCDLibrary();
WINUSERAPI VOID WINAPI SetCDCallbackProc( CDDeviceChangePROC lpProc );
WINUSERAPI int WINAPI GetDeviceNumber();
WINUSERAPI int WINAPI EnumDevice( int);

// CD Device Operate function below
WINUSERAPI int WINAPI USBCDReset( int ID );
WINUSERAPI int WINAPI USBCDMoveto( int ID, int Index );
WINUSERAPI int WINAPI USBCDGetCDDown( int ID );
WINUSERAPI int WINAPI USBCDLEDON( int ID );
WINUSERAPI int WINAPI USBCDLEDOFF( int ID );
WINUSERAPI int WINAPI USBCDGetStatus( int ID );
}
#endif

now for the regular functions to transform them to use in c# its

/////////////////////////////////////
using System.Runtime.InteropServices;

[DllImport("USBCDDLL.dll")]
private static extern void InitUSBCDLibrary();
//////////////////////////////////////////////

not very difficult, right. But how would I use the "callback" thingie?
please any code example would be very helpfull.

thx
Nov 16 '05 #1
1 1962
Bart,
But how would I use the "callback" thingie?


You use a delegate.

delegate void CDDeviceChangePROC(int i);

[DllImport("USBCDDLL.dll")]
private static extern void SetCDCallbackProc(CDDeviceChangePROC
lpProc);

Just make sure that the delegate object you pass in to
SetCDCallbackProc is kept alive (you hold a reference to it) so it
doesn't get garbage collected as long as it's needed by the unmanaged
API.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roy Pereira | last post by:
I have an application that is composed of a set of "Content" dlls and a viewer application. The viewer calls a standard set of functions that are present in all the dlls. I maintain this by...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
4
by: Doug | last post by:
I am working on an existing .NET (C Sharp) component that had a com interface that was used by a VB component. When it was originally written, it had the SSEAssemblyCom class below - minus the two...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
6
by: Alex Sedow | last post by:
Example 1 interface I { string ToString(); } public class C : I { public void f() {
20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my Interface that my DAL-objects implementing the...
2
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators ","...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interfaceâ€. In a functional language, a function can be specified by its name and parameter specs....
8
by: rn5a | last post by:
Suppose I have the following class code: Imports System Imports System.Data Imports System.Data.SqlClient Public Class DBSettings Private sqlCmd As SqlCommand Private sqlConn As...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.