473,388 Members | 1,383 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,388 software developers and data experts.

C# DLLImport

1
I try to use a dll in C#.
My problem are the pointers (like int *TimeToWait) and the struct (TLumax_Point *Points) How can i use them.
Maybe someone can give me an Example (of safe code :-)).

// ----------------------------------------------------------
int __stdcall Lumax_SendFrame(int Handle, TLumax_Point *Points, int NumOfPoints, int ScanSpeed, int UpdateMode, int *TimeToWait)

int __stdcall Lumax_WaitForBuffer(int Handle, int Timeout, int *TimeToWait, int *BufferChanged)

//-----------------------------------------------------------

//An Example in C:
typedef struct
{
unsigned short Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8, TTL;
} TLumax_Point;

TLumax_Point Lumax_Points[4000];

typedef int __stdcall (*tLumax_SendFrame)(int, TLumax_Point *, int, int, int, int *);
typedef int __stdcall (*tLumax_StopFrame)(int);
typedef int __stdcall (*tLumax_WaitForBuffer)(int, int, int *, int *);
typedef int __stdcall (*tLumax_GetPhysicalDevices)();
typedef int __stdcall (*tLumax_OpenDevice)(int, int);
typedef int __stdcall (*tLumax_CloseDevice)(int);

tLumax_SendFrame fLumax_SendFrame;
tLumax_StopFrame fLumax_StopFrame;
tLumax_WaitForBuffer fLumax_WaitForBuffer;
tLumax_GetPhysicalDevices fLumax_GetPhysicalDevices;
tLumax_OpenDevice fLumax_OpenDevice;
tLumax_CloseDevice fLumax_CloseDevice;

void main(void)
{
int i, j, PointCounter, LumaxHandle, TimeToWait, BufferChanged;
HINSTANCE DllHandle;

DllHandle = LoadLibrary("lumax.dll"); // open DLL
if (DllHandle != NULL)
{ // DLL successfully opened -> get functions
fLumax_SendFrame = (tLumax_SendFrame)GetProcAddress(DllHandle, "Lumax_SendFrame");
fLumax_StopFrame = (tLumax_StopFrame)GetProcAddress(DllHandle, "Lumax_StopFrame");
fLumax_WaitForBuffer = (tLumax_WaitForBuffer)GetProcAddress(DllHandle, "Lumax_WaitForBuffer");
fLumax_GetPhysicalDevices = (tLumax_GetPhysicalDevices)GetProcAddress(DllHandl e, "Lumax_GetPhysicalDevices");
fLumax_OpenDevice = (tLumax_OpenDevice)GetProcAddress(DllHandle, "Lumax_OpenDevice");
fLumax_CloseDevice = (tLumax_CloseDevice)GetProcAddress(DllHandle, "Lumax_CloseDevice");
if ( (fLumax_SendFrame != NULL)
&& (fLumax_StopFrame != NULL)
&& (fLumax_WaitForBuffer != NULL)
&& (fLumax_GetPhysicalDevices != NULL)
&& (fLumax_OpenDevice != NULL)
&& (fLumax_CloseDevice != NULL))
{ // now we have all functions
i = fLumax_GetPhysicalDevices(); // get number of connected Minilumax devices
if (i > 0)
{ // there's at least 1 Minilumax device
LumaxHandle = fLumax_OpenDevice(1, 0); // open the first available Minilumax card
if (LumaxHandle != 0)
{ // card successfully opened
// now, prepare the output buffer (draw 3 lines colored R/G/B)
PointCounter = 0;
for (i = 0; i < 3; i++) // loop for colors
{
for (j = 0; j < 100; j++) // each line consists of 100 points
{
Lumax_Points[PointCounter].Ch1 = j * 600; // x position
Lumax_Points[PointCounter].Ch2 = i * 10000; // y position
Lumax_Points[PointCounter].Ch3 = (i == 0) ? 65535 : 0; // red
Lumax_Points[PointCounter].Ch4 = (i == 1) ? 65535 : 0; // green
Lumax_Points[PointCounter].Ch5 = (i == 2) ? 65535 : 0; // blue
PointCounter = PointCounter + 1;
}
}

// before we can send the frame to the Minilumax card, we have to ask if the buffer is free
do
{
// we could do something useful here, like calculation of new frame data
// ...
// ...
// ...
fLumax_WaitForBuffer(LumaxHandle, 0, &TimeToWait, &BufferChanged);
}
while (BufferChanged == 0); // repeat loop until the buffer is free
fLumax_SendFrame(LumaxHandle, Lumax_Points, PointCounter, 10000, 0, 0); // send frame
Sleep(5000); // wait 5 seconds
fLumax_StopFrame(LumaxHandle); // stop laser output
fLumax_CloseDevice(LumaxHandle); // close Minilumax device
}
}
}
}
}
Jan 11 '08 #1
0 2024

Sign in to post your reply or Sign up for a free account.

Similar topics

15
by: Jim | last post by:
I am extremely frustrated. I am building c# application for a call center and am using a third party API to access some hardware. When develop and test my class using the windows console the...
6
by: Tim Mulholland | last post by:
Whats the correct C# datatype (or marshalling function or something) to use when you're importing a function that has a signature similar to char* FuncA(char c) ? Assuming you know that...
9
by: Ole Christensen | last post by:
I'm trying to make a sort of conditional compilation in my C# code because my app is intended to run on both a Pocket PC and on a normal desktop PC. My code uses a call to an API function that on...
3
by: Mark Jerde | last post by:
I'm sill learning VS .NET 2003, not an expert yet. I'm calling an unmanaged C++ DLL from C# using . When the whole project is done I will be calling a total of 5 C++ DLLs from C#. All the DLLs...
1
by: Brian Anderson | last post by:
Hello, I have a native, C++ console app that uses ~26MB of RAM when it runs. It uses quite a lot of RAM to make some math but will never xceed 26MB. Now I've made a dll out of this code and...
2
by: Brian Anderson | last post by:
Hello, is it possible to use DllImport to call a DLL in ASP.NET ? Or is it necessarry that my DLL has to be copied into \System32 ? My DLL is a native C++ 7.1 DLL (not managed, no COM, no...
2
by: Ed | last post by:
Hello, dear all, I often see these two import usage in the code. Both are the interface to use the Dll library. I think they are the same. Normally P/Invoke means using the to import the dll....
1
by: kardon33 | last post by:
Let me explain my problem, Im currently trying to use a Perl module that was built for a Windows OS that uses a .dll and .lib file. I have obtained the c header files that the modules were built...
9
by: jjones7947 | last post by:
Am doing a JNI wrap on a C++ API, am using VC7 and Eclipse. In preparation, I created a C++ executable which mimicked the flow of the JNI, i.e. a driver file which called methods in file with methods...
1
by: elke | last post by:
Hi, I want to use an unmanaged dll in C# .net and I'm having some troubles witch a function that should return an array. I'm new at this, so I don't know what I'm doing wrong. Here is some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.