[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Marshal'ing help - C++ DLL Call to C#

Posted on 2007-11-20
23
Medium Priority
?
340 Views
Last Modified: 2013-12-17
I have a C++ DLL that I need help converting into C#.

My code compiles correctly, and I can run it, I just don't get the video data back into the "PictureBox" form control.

In the C++ application it uses "UpdateData(TRUE);" to invalidate the form control and show the video data. Am I missing the equivalent of that call in the C# code?

My code is "Attach Code Snippet" area:


Code snippet deleted at member request

Open in new window

0
Comment
Question by:VirtueTech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 9
23 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20322974
UpdateData(TRUE) will copy the contents of some controls in your form to related data member in the same form.
Them are related using the Class Wizard in VC++
0
 

Author Comment

by:VirtueTech
ID: 20323047
How do I replicate that in C#?

I need to use this C++ code in C#
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20323204
define your own UpdateData method, and some fields related with controls that contain data. inside this method, copy the contents of the controls into the data fields.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:VirtueTech
ID: 20323250
Based off the code I attached...is this what I'm missing in my C# code?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20323431
Indeed you don't need this stuff, .net has a different approach than MFC for data recovering from controls.
The problem is not in the code you have posted. It is outside, where the form is created, invoked, and then accessed for data extraction.
0
 

Author Comment

by:VirtueTech
ID: 20323590
I'm sorry...I'm not following how to get the control to update the data from the DLL calls.

I see you mentioned creating my own UpdateData method.

The DLL in the C++ app keeps sending data to the control, video data, how do I replicate this in my own updatedata method?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20323625
UpdateData call the DoDataExchange method of your dialog, could you post it?
0
 

Author Comment

by:VirtueTech
ID: 20323730
post what?  I posted all the code I had for this.

the only thing you don't see if the form, which just has a PictureBox that I'm trying to display the video in.
0
 

Author Comment

by:VirtueTech
ID: 20323732
The FORM nor the PICTUREBOX has a DoDataExchange event
0
 

Author Comment

by:VirtueTech
ID: 20323780
Sorry...I got you now...here is the DoDataExchange method of the C+ app:

m_video5 and IDC_STATIC5 was the control to play the video over
void CDialogWin::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialogWin)
	DDX_Control(pDX, IDC_SLIDER4, m_hue);
	DDX_Control(pDX, IDC_SLIDER3, m_saturation);
	DDX_Control(pDX, IDC_SLIDER2, m_contrast);
	DDX_Control(pDX, IDC_SLIDER1, m_brightness);
	DDX_Control(pDX, IDC_COMBO1, m_windowCtrl);
	DDX_Control(pDX, IDC_STATIC8, m_video8);
	DDX_Control(pDX, IDC_STATIC7, m_video7);
	DDX_Control(pDX, IDC_STATIC6, m_video6);
	DDX_Control(pDX, IDC_STATIC5, m_video5);
	DDX_Radio(pDX, IDC_TCP, m_linktype);
	DDX_Text(pDX, IDC_IPADDRESS, m_ipadd);
	DDX_Text(pDX, IDC_SHOWNUM, m_shownum);
	DDX_Radio(pDX, IDC_DELAY1, m_delaytype);
	DDX_Radio(pDX, IDC_SHOWMODE1, m_showmode);
	DDX_Radio(pDX, IDC_RADIOBFRAM0, m_bframenum);
	DDX_Text(pDX, IDC_STATICFRAME, m_frameshow);
	//}}AFX_DATA_MAP
}

Open in new window

0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20323782
I am assuming your CDialogWin is a MFC's CDialog derived class... is it?
0
 

Author Comment

by:VirtueTech
ID: 20323803
yes
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20323817
OK, there are some many controls, UpdateData(TRUE) will copy the contents of:

IDC_TCP or any of the subsequent radios to m_linktype integal member
IDC_IPADDRESS textbox to m_ipadd string member
IDC_SHOWNUM textbox to m_shownum string member
IDC_DELAY1 or any of the  subsequent radios to m_delaytype integal member
IDC_SHOWMODE1 or any of the subsequent radios to m_showmode integal member
IDC_RADIOBFRAM0 or any of the subsequent radios to m_bframenum integal member
IDC_SHOWNUM textbox to m_frameshow string member

Do you want to translate this functionality to your C# app?
0
 

Author Comment

by:VirtueTech
ID: 20323833
DDX_Control(pDX, IDC_STATIC5, m_video5);

This is the only control I'm really interested in. This is the control the video is shown in
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 2000 total points
ID: 20323839
Then UpdateData() is unuseful...
0
 

Author Comment

by:VirtueTech
ID: 20323876
If I remove the UpdateData(TRUE); from the C++ app, the video will not show.

So I'm asusming it must be used to tell the DLL to use the IDC_STATIC5 to show the video
0
 

Author Comment

by:VirtueTech
ID: 20323913
Maybe it works...and the C# is wrong.

Did I convert the "CLIENT_VIDEOINFO" struct properly? Will the DLL understand the data from the C# app?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20323948
>>If I remove the UpdateData(TRUE); from the C++ app, the video will not show.
That's because the controls are initilized there, but in a C# app it is not needed.

>>Maybe it works...and the C# is wrong.
I don't understand this. It is very unlikely that a programming language is wrong.

>>Did I convert the "CLIENT_VIDEOINFO" struct properly?
>>Will the DLL understand the data from the C# app?
As far I have seen, yes
0
 

Author Comment

by:VirtueTech
ID: 20324010
Maybe the DLL is expecting a _HWND object and not a C# IntPtr

Do I marshal that?
0
 

Author Comment

by:VirtueTech
ID: 20324025
>>Maybe it works...and the C# is wrong.
I don't understand this. It is very unlikely that a programming language is wrong.

I meant maybe my C# code is incorrect in how I converted the C++ struct and sent it to the DLL. Now the DLL has to send me back the Video data to display in my pcitureBox control. It is expecting a HWND, I'm using a C# IntPtr.
0
 

Author Comment

by:VirtueTech
ID: 20324698
Jaime, even though we didn't come to a conclusion,  thanks for your help.

Should I restart this question over to get other users to answer?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20324761
Thanks,
You need to send more information about the C++ code, the C# code, the specific library you are trying to use.
Sometimes it is not easy to diagnostic if the patient nudes clothe by clothe.
0
 

Author Comment

by:VirtueTech
ID: 20326043
Hey,

I found the problem. It ended up being the way I converted the STRUCT. I had to use "byte" for the DLL's bytes, not int

Same for the BOOL...I needed to use int.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question