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

Home Posts Topics Members FAQ

Unmanaged C++ Void*

I have a C++ DLL that I need to access from VB.NET. The function I am
trying to call is declared like this:

void* PASCAL iidc_lockdata( HIIDC, long frame = -1 )

This function returns a pointer to unsigned chars

I am able to find the size of the array out. It is usually 128800 to
use as an example if it helps.

I have declared the interface for my VB.NET as follows:

Private Declare Function _iidc_lockdata Lib "iidcapi_SONY.dll" Alias
"#37" (ByVal HIIDC As Int32, ByVal frame As Int32) As
System.Runtime.InteropServices.GCHandle

and also I have tried it as

Private Declare Function _iidc_lockdata Lib "iidcapi_SONY.dll" Alias
"#37" (ByVal HIIDC As Int32, ByVal frame As Int32) As IntPtr

(1) My first question is, how do I declare the function, should I use
GCHandle or IntPtr or something else?

As far as calling the function goes, I have tried this:

Dim gch As System.Runtime.InteropServices.GCHandle
gch = New System.Runtime.InteropServices.GCHandle
Dim lBufSz As Int32 = camera.currentDataFrameBytes(m_hCamera)
gch.Alloc(lBufSz)
Try
gch = camera.lockdata(m_hCamera, -1)
gch.Free()
Catch ex As Exception
MsgBox(ex.Message)
End Try

FYI the function camera.lockdata is a mapped function and it is as
follows:

Public Function lockdata(ByVal HIIDC As Int32, ByVal frame As Int32)
As System.Runtime.InteropServices.GCHandle
Return _iidc_lockdata(HIIDC, frame)
End Function
and I get "Object reference not set to an instance of an object"

(2) How would I get the data?

I have been really struggling with this.

Thanks,
Mike Dixon

Jun 7 '06 #1
2 1627
Mike,
(1) My first question is, how do I declare the function, should I use
GCHandle or IntPtr or something else?
IntPtr

(2) How would I get the data?


System.Runtime.InteropServices.Marshal.Copy

Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jun 7 '06 #2
Hi,

The function should return an intptr. You should be able to use
marshal.ptrtostructure or one of the marshal.pointertostring function to get
the data.

http://msdn2.microsoft.com/en-us/lib...l_members.aspx

Ken
---------------

"Frustrated" wrote:
I have a C++ DLL that I need to access from VB.NET. The function I am
trying to call is declared like this:

void* PASCAL iidc_lockdata( HIIDC, long frame = -1 )

This function returns a pointer to unsigned chars

I am able to find the size of the array out. It is usually 128800 to
use as an example if it helps.

I have declared the interface for my VB.NET as follows:

Private Declare Function _iidc_lockdata Lib "iidcapi_SONY.dll" Alias
"#37" (ByVal HIIDC As Int32, ByVal frame As Int32) As
System.Runtime.InteropServices.GCHandle

and also I have tried it as

Private Declare Function _iidc_lockdata Lib "iidcapi_SONY.dll" Alias
"#37" (ByVal HIIDC As Int32, ByVal frame As Int32) As IntPtr

(1) My first question is, how do I declare the function, should I use
GCHandle or IntPtr or something else?

As far as calling the function goes, I have tried this:

Dim gch As System.Runtime.InteropServices.GCHandle
gch = New System.Runtime.InteropServices.GCHandle
Dim lBufSz As Int32 = camera.currentDataFrameBytes(m_hCamera)
gch.Alloc(lBufSz)
Try
gch = camera.lockdata(m_hCamera, -1)
gch.Free()
Catch ex As Exception
MsgBox(ex.Message)
End Try

FYI the function camera.lockdata is a mapped function and it is as
follows:

Public Function lockdata(ByVal HIIDC As Int32, ByVal frame As Int32)
As System.Runtime.InteropServices.GCHandle
Return _iidc_lockdata(HIIDC, frame)
End Function
and I get "Object reference not set to an instance of an object"

(2) How would I get the data?

I have been really struggling with this.

Thanks,
Mike Dixon

Jun 7 '06 #3

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

Similar topics

7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
5
by: Chris Kiechel | last post by:
I am writing a .NET Windows application and it needs to perform DDE calls to a legacy system. I created a C++ unmanaged class that performs the actual DDE connection and communication. However,...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
2
by: Brett Styles | last post by:
Hi Guys, I am trying to access a class in an unmanaged dll. I have created a wrapper managed class to access the functions I need but no matter what I try from the MSDN samples I can not get it to...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
7
by: Carl | last post by:
Hello, I noticed an unexplained (for me) behaviour while wrapping unmanaged virtual methods. This is the test situation: An unmanaged class has four methods defined DoIt1 .. DoIt4. Each...
2
by: bonk | last post by:
Hello, I have a managed type that defines an Event as one of its public members. Is it possible for an unmanaged c++ class to register to that event ? How can an unmanaged classmethod be called...
13
by: bonk | last post by:
Hello, I am trying to create a dll that internally uses managed types but exposes a plain unmanaged interface. All the managed stuff shall be "wrapped out of sight". So that I would be able to...
5
by: akash | last post by:
I'm having problems calling an unmanaged class from a managed wrapper. I suspect I'm missing something obvious, as I'm unfamiliar with C++ and classes are very simple. My unmanaged class is as...
6
by: Aston Martin | last post by:
Hi All, ********************** My Situation ********************** I am working on project that involves passing a structure to unmanaged code from .Net world (well using C#). Perhaps an example...
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
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...
1
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,...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
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.

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.