473,473 Members | 1,782 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PInvoke void * parameter

4 New Member
Here is the unmanged definition:
Expand|Select|Wrap|Line Numbers
  1.  
  2. //============================================================================
  3. // DcamCapture()
  4. // Start to acquire one image from the camera.
  5. // ---------------------------------------------------------------------------
  6. // [Argument]
  7. // pImageBuff : /O: Specify the start address in the buffer where image
  8. // data is to be stored.
  9. // nBuffSize :I/ : Specify the buffer size (number of bytes).
  10. // [Return values]
  11. // If the function succeeds the return value is TRUE (1).
  12. // If the function fails the return value is FALSE (0).
  13. // To obtain detailed error information, use the DcamGetLastError function.
  14. // [Note]
  15. // 1. This function issues an instruction to start image acquisition.
  16. // Since image acquisition is not complete even when this function ends,
  17. // use the DcamWait function to check whether image acquisition is complete.
  18. // 2. The necessary buffer size can be obtained with the DcamGetFrameBytes function.
  19. //============================================================================
  20. _DCAMLIBEXPORT BOOL _DCAMLIBSTDCALL DcamCapture( LPVOID pImageBuff, INT nBuffSize );
  21.  
Here is my C# code which does not work:
Expand|Select|Wrap|Line Numbers
  1. class DCamLIB
  2. {
  3. private IntPtr ImageBuffer;
  4.  
  5. public DCamLIB()
  6. {
  7. ImageBuffer = new IntPtr( 0 );
  8. }
  9.  
  10. [DllImport( "DCamLIB.dll" )]
  11. private static extern bool DcamCapture( out IntPtr imageBuffer, Int32 bufferSize );
  12.  
  13. public void Capture( Int32 bufferSize )
  14. {
  15. if ( !DcamCapture( out ImageBuffer, bufferSize ) )
  16. {
  17. throw new DCamLIBException( this );
  18. }
  19. }
  20. }
  21.  
No matter what ImageBuffer = 0.

Ideas?
Mar 14 '09 #1
8 4880
tlhintoq
3,525 Recognized Expert Specialist
// 2. The necessary buffer size can be obtained with the DcamGetFrameBytes function.
Question 1: What kind of camera is this?
Question 2: Are you receiving a buffersize from the above function that makes sense for the size of the image you are expecting?
Mar 14 '09 #2
jmcpeak
4 New Member
> What kind of camera is this?
X-Ray

> Are you receiving a buffersize from the above function that makes sense for the size of the image you are expecting?
Yes, it is is returning the correct width and height variables - 1000 x 1500
Mar 14 '09 #3
tlhintoq
3,525 Recognized Expert Specialist
The function doesn't look like it would be turning H & W values, judging by its name: GetFrameBytes. It looks like it would be returning a single number that is the size of the buffer to hold the image data. You would then use your knowledge of the expected data to translate all those bytes to an image (height, width, color depth, header size)
Mar 14 '09 #4
tlhintoq
3,525 Recognized Expert Specialist
// 1. This function issues an instruction to start image acquisition.
// Since image acquisition is not complete even when this function ends,
// use the DcamWait function to check whether image acquisition is complete.
I don't see where you are checking the DcamWait function.
Mar 14 '09 #5
jmcpeak
4 New Member
The real issue I can't solve is how to pass a void * as a parameter to the dll.
Expand|Select|Wrap|Line Numbers
  1. [DllImport( "DCamLIB.dll" )]
  2. private unsafe static extern bool DcamCapture( int* imageBuffer, Int32 bufferSize );
  3.  
  4. public unsafe void CaptureReverseX( Int32 bufferSize )
  5. {
  6.     fixed ( int* buf = new int[ bufferSize ] )
  7.     {
  8.         if ( !DcamCapture( ImageBuffer, bufferSize ) )
  9.         {
  10.             throw new DCamLIBException( this );
  11.         }
  12.         // Here the pointer buf is defined, but the value is still 0
  13.         // It's like the DcamCapture() method does not populate buf
  14.     }
  15. }
  16.  
Mar 14 '09 #6
tlhintoq
3,525 Recognized Expert Specialist
The real issue I can't solve is how to pass a void * as a parameter to the dll.
A void pointer ???

I don't see where you are checking the DcamWait function.
Are you checking the DcamWait function before you try to get the data out of the buffer?
Mar 14 '09 #7
jmcpeak
4 New Member
I got it working, needed to change a setting - set the trigger mode to internal. Using fixed worked great.
Mar 15 '09 #8
cooldj
1 New Member
HDCAM is a typedef struct tag_dcam* HDCAM


In DCAM-API , HDCAM is one of the input arguments.

which is declare as...
// declaration of DCAM helper function
HDCAM dcamcon_init_open();

In main function it can Initialize as...
HDCAM hdcam;

& call as...
// initialize DCAM-API and get HDCAM camera handle.
hdcam = dcamcon_init_open();


How I can write code in c# if I want to access HDCAM?
Dec 14 '11 #9

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

Similar topics

3
by: msnews.microsoft.com | last post by:
Hi i am using User32.dll in Visual stdio 2005. public static extern long SetActiveWindow(long hwnd); public static extern long keybd_event(byte bVk, byte bScan, long dwFlags,
6
by: Pucca | last post by:
I have a program that originally compiles into a exe file. I changed the compile option to generate dll file. This program calls a com component. Can I use pinvoke in C# to call it? The...
2
by: MyCrystalGift | last post by:
Hi, I have an old C++ GUI Application CPPAPP.exe that calls a C DLL library RULE.DLL through a C++ class wrapper LoadRule.CPP. Now I need to call the C DLL RULE.DLL from C# GUI application...
6
by: Karthik V | last post by:
In a certain dll, there is this function: typedef DWORD STDAPICALLTYPE SOMEFUNC(VOID *pHandle, IProgress *pProgress); where IProgress is class IProgress { public: virtual void Update(UINT...
11
by: Daniel Bass | last post by:
Greetings! I'm trying to call this method in a c# app... SNAPIDLL_API int __stdcall SNAPI_SetCapabilitiesBuffer(HANDLE DeviceHandle, unsigned char *pData, long max_length); So far I've got...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
0
by: Aldev | last post by:
Hi There, I am quite new to PInvoke and calling COM functions from C#. I have managed so far to call some unmanaged functions ib my C++ dll from my C# code but at the moment I am having trouble...
3
by: not_a_commie | last post by:
The CLR won't garbage collect until it needs to. You should see the memory usage climb for some time before stabilizing. Can you change your declaration to use the 'out' keyword rather than a 'ref'...
5
by: =?Utf-8?B?SmVzc2ljYQ==?= | last post by:
Hello, I have a pInvoke question. This is the C function that is exported from one of the C dll, extern __declspec(dllexport) IM_RET_CODE ST_import (IM_MODE mode, char *filename,...
2
by: grndvl1 | last post by:
Here is my issue, I am very new to C# and want to invoke a custom dll that I can't register using regsvr32. I figured out I need to use PInvoke somehow but need help since all the methods return...
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
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
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.