C# to C++.Net Win Forms

Lord Banshee

Golden Member
Sep 8, 2004
1,495
0
0
OK i am trying to write an application to interface with my USB port on an FPGA device. The USB chip is a Cypress FX2 and they have a .Net Library but all the examples are in C#. It doesn't help as i am mostly all my programming is in oldschool C/C++. But i have gotten used to make Windows application via the C++.Net Windows Forms. But i don't understand how most of it is setup i just know how to use it : / .

Now i have this code from the Cypress Help file that is suppose to just initialize the USB library.
using CyUSB;

public class Form1 : System.Windows.Forms.Form
{

USBDeviceList usbDevices;

public Form1()
{

InitializeComponent();

App_PnP_Callback evHandler = new App_PnP_Callback(PnP_Event_Handler);
usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB, evHandler);

// Get the first device having VendorID == 0x04B4 and ProductID == 0x8613
CyUSBDevice myDev = usbDevices[0x04B4, 0x8613] as CyUSBDevice;

}


public void PnP_Event_Handler(IntPtr pnpEvent, IntPtr hRemovedDevice)
{

if (pnpEvent.Equals(CyConst.DBT_DEVICEREMOVECOMPLETE))
{

usbDevices.Remove(hRemovedDevice);
// Other removal event handling

}

if (pnpEvent.Equals(CyConst.DBT_DEVICEARRIVAL))
{

usbDevices.Add();
// Other arrival event handling

}

}

}

Now i know my C++.net win app has these major sections

includes : the namespaces

namespace "current project"
{
public ref class Form1: public System::Windows::Forms::Form
{

public:Form1(){calls the void InitializeComponent(void) function}

protected:~Form1(){... }

private: All the Form objects class defines i am guessing

void InitializeComponent(void) function ... all the form object properties

private: event functions for the form objects

}
}


So anyone know how to organize the above code into the correct section so it will work correctly? I have tried some ways the the best i could do is 3 errors which did not like these lines:

evHandler = gcnew App_PnP_Callback(PnP_Event_Handler);
usbDevices = gcnew USBDeviceList(CyConst.DEVICES_CYUSB, evHandler);

these are the 3 errors

error C3867: 'My3DLaserScanner::Form11::pnP_Event_Handler': function call missing argument list; use '&My3DLaserScanner::Form11::pnP_Event_Handler' to create a pointer to member
error C3350: 'CyUSB::App_PnP_Callback' : a delegate constructor expects 2 argument(s)
error C3867: 'My3DLaserScanner::Form11::evHandler': function call missing argument list; use '&My3DLaserScanner::Form11::evHandler' to create a pointer to member



any help would be great.

Thanks,
Chris

 

Lord Banshee

Golden Member
Sep 8, 2004
1,495
0
0
I think i am figuring it out if i not include all the PnP and evHandle stuff.. i can so far find the device and show its name lol... it is a start :)

*edit*

now that i ignored all the PnP Stuff i was able to send and receive some data... finally woot!!!

But i wonder if anyone has some good managed books that could explain some of these newer extensions and keywords to C++.Net? Some critical syntax problems were solved with a program, demo i used, called Instant C++ which converts C# code into C++.
 

postmortemIA

Diamond Member
Jul 11, 2006
7,721
40
91
If you know C++, really C# syntax is nothing new..seems like you don't have knowledge of event handling, and that is not unique to C#, it is common for any GUI development.
 

Lord Banshee

Golden Member
Sep 8, 2004
1,495
0
0
I've played with C# some, but not enough to do the project i want to do.... i kinda have a deadline....

But on other notes you would be correct about not knowing too much about event handling.. I feel said about all the stuff i don't know really as i am on my last year of college for EE and i would say i know more than 80% of the other EE at my level in programming... The only class i had a college that was required for programming was C++ and this just went into classes and thats about it. I did have other classes that you learn ASM for MCU but unfortunately that does help me interface with what everyday people use... Windows lol. Oh well i keep trying to learn as much as i can on my own. Just wish we had more programming classes for EE to at least make clean interfaces to the devices we do know how to make.
 

postmortemIA

Diamond Member
Jul 11, 2006
7,721
40
91
Originally posted by: Lord Banshee
I've played with C# some, but not enough to do the project i want to do.... i kinda have a deadline....

But on other notes you would be correct about not knowing too much about event handling.. I feel said about all the stuff i don't know really as i am on my last year of college for EE and i would say i know more than 80% of the other EE at my level in programming... The only class i had a college that was required for programming was C++ and this just went into classes and thats about it. I did have other classes that you learn ASM for MCU but unfortunately that does help me interface with what everyday people use... Windows lol. Oh well i keep trying to learn as much as i can on my own. Just wish we had more programming classes for EE to at least make clean interfaces to the devices we do know how to make.

that what you described in last sentence would be more like computer engineering.

Codeproject.com has good guides, appropriate article might help you a lot.
 

Lord Banshee

Golden Member
Sep 8, 2004
1,495
0
0
Yeah i guess Comp Eng "might" teach you some skills that i have yet to learn but at my university the only classes of Comp Eng degree that is different from the EE degree and i have not already taken as a tech elective is "OS Design" and "Data Structures" i believe.

But anyway thanks for the link looks like some good examples.