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

Using C++ library in C#

Hi.

I need help with my code.
I'm trying to run unmanaged code from my C# code.


C++ Code
Expand|Select|Wrap|Line Numbers
  1. Result_t oemGetImage(PBYTE pImageBuffer,
  2.                      PDWORD pdwSize, WORD nTop,
  3.                      WORD nLeft, WORD nRight,
  4.                      WORD nBottom, WORD nSkip,
  5.                      WORD nBits, FileFormat_t nFormat,
  6.                      WORD nWhiteValue,
  7.                      WORD nExposeAttempts, WORD nGap,
  8.                      BOOL Invert, void (*fpProgress) (WORD));
I don't know what to do with pImageBuffer, pdwSize or void (*fpProgress) (WORD)).

In C++ I execute this function like this:
Expand|Select|Wrap|Line Numbers
  1. BYTE *pBufor;
  2. pBufor = new BYTE[MAX_IMAGE_SIZE];
  3.  
  4. DWORD *pSize; 
  5.     pSize = new DWORD; 
  6.  
  7. oemGetImage (pBufor,pSize, 0, 0, 200, 200, 1, 8, FF_RAW_GRAY, 200, 100, 55, false, NULL);
FF_RAW_GRAY is an enum with value of 1.

How can I declare pBufor which is a pointer to byte array?
And what to do with void (*fpProgress) (WORD))??

Thank you, for all your help.
Jun 20 '12 #1

✓ answered by GigaKatowice

I managed to run this function with help from other forum.
My definition for this function looks like this:

Expand|Select|Wrap|Line Numbers
  1.   private extern static int oemGetImage([In, Out]byte[] pImageBuffer,
  2.   ref uint pdwSize, uint nTop,
  3.   uint nLeft, uint nRight,
  4.   uint nBottom, uint nSkip,
  5.   uint nBits, uint nFormat,
  6.   uint nWhiteValue,
  7.   uint nExposeAttempts, uint nGap,
  8.   bool Invert, [MarshalAs(UnmanagedType.FunctionPtr)]Progress fpProgress);
  9.  
  10.   public delegate void Progress(ushort us);
and execution

Expand|Select|Wrap|Line Numbers
  1.  byte[] pBufor = new byte[width * height];
  2.  uint pSize = 0;
  3.  oemGetImage(pBufor, ref pSize, 0, 0, _width, _height, 1, 8, 1, 220, 50, 35, false, null);

1 2035
I managed to run this function with help from other forum.
My definition for this function looks like this:

Expand|Select|Wrap|Line Numbers
  1.   private extern static int oemGetImage([In, Out]byte[] pImageBuffer,
  2.   ref uint pdwSize, uint nTop,
  3.   uint nLeft, uint nRight,
  4.   uint nBottom, uint nSkip,
  5.   uint nBits, uint nFormat,
  6.   uint nWhiteValue,
  7.   uint nExposeAttempts, uint nGap,
  8.   bool Invert, [MarshalAs(UnmanagedType.FunctionPtr)]Progress fpProgress);
  9.  
  10.   public delegate void Progress(ushort us);
and execution

Expand|Select|Wrap|Line Numbers
  1.  byte[] pBufor = new byte[width * height];
  2.  uint pSize = 0;
  3.  oemGetImage(pBufor, ref pSize, 0, 0, _width, _height, 1, 8, 1, 220, 50, 35, false, null);
Jun 21 '12 #2

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

Similar topics

1
by: Doug Tolton | last post by:
At my company we have a program that parses through certain types of electronic files and stores the information in plain text. E-mail poses an interesting problem for us, because most of the text...
10
by: David Soukal | last post by:
Hello, I have an interesting problem that I'm tackling with. I'm sure there must be some obvious solution... I have this big project. It's composed of several *.lib modules. Now, one of the...
4
by: junky_fellow | last post by:
what is the purpose of using library functions ? How could i know whether a particular function that i want to write already exists in the library ? Are there some standard functions which...
1
by: vertigo | last post by:
Hello I write program in C#. I wanted to load mp3 files to read it's size, title and others. So i downloaded id3lib from: id3lib.sourceforge.net, compiled it using Visual Studio NET (with...
1
by: stachurr | last post by:
Hello I'm new in C, And I want to compile program which use extern function. How to do it because I always got error. Undefined first referenced symbol ...
1
by: A.Dagostino | last post by:
hi everyone i have developed a library in vb6 to import an excel file ftom client to a sql 2000 table on the server.This object must run at server. How can i create this object on a web asp...
4
by: =?Utf-8?B?Sm9l?= | last post by:
I have a .NET class library called NorthwindLib and a class called Customer. I have a web server that exposes a web method GetCustomer() and returns a NorthwindLib.Customer object. I want to...
4
by: almon | last post by:
I am beginner in programming.I want to make a program which reads pdf documents.For this (after googling) I found that a library pdflib is uded to do so.but i dont know how to use any library.
4
by: Reshmi | last post by:
Hi, I have this C code which does complex number arithmetic. When I try to write a similar file for C++, it says that "creal’ was not declared in this scope". Can anyone give a better idea to...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.