VC++ DLL LIB and OCX in C# Win Form Application
-
Hi, I purchased an USB based oscilloscope DSO-2150 from Hantek. Along with it came the VC++ DLLs (dll, lib and ocx). I need to create a Winform application using C# Visual Studio Express Edition. Please tell me is it possible to use VC++6 DLL in a C# appllication and if yes How? Following is scrap from the manual provided with the DLL files.
DSO-XXXX USB SDK Manual
SDKXXXX.dll (VC++ 6.0)
Define struct
struct PictureRange{ // Be used for draw grid
WORD width; // the width of display range
WORD height; // the height of display range
WORD left; //the left of display range
WORD right; //the right of display range
WORD top; //the top of display range
WORD bottom; //the bottom of display range
};
struct ControlStruct{ //save the control data
WORD TriggerSource; //the trigger source
WORD SelectedChannel; // the display channel
WORD Timebase; // timebase
WORD TriggerPosition; // the trigger vertical position “0%,25%,50%,75%,100%”
WORD DataLengh; // its value is 1 or 2, if BufferSize = 10, Datalengh = 1, else Datalengh =2
WORD BufferSize ; //Its value is 10,32 or 64
WORD isAlt; //If ALT trigger, its value is 1, else 0.
};
struct LeversStruct{ //save position
WORD Ch1Position; // the ch1 waveform horizontal position
WORD Ch2 Position; // the ch2 waveform horizontal position
WORD Ch1TriggerPosition; // the ch1 trigger position
WORD Ch2TriggerPosition; // the ch2 trigger position
WORD EXTTriggerPosition; // the EXT trigger position
};
struct StateStruct{
WORD Ch1Filt; // ch1 filter
WORD Ch2Filt; //ch2 filter
WORD TriggerFilt; // trigger filter
WORD TriggerMode; //trigger mode (AUTO, NORMAL, SINGLE)
WORD TriggerSlope; //trigger slope (rising edge, failing edge)
};
struct LineColor{ // the waveform color
WORD R;
WORD G;
WORD B;
};struct AutosetStruct{ //save the autoset data
WORD WhichChannel; //which channel will autoset
WORD Ch1Voltage; //Ch1 autoset voltage
WORD Ch2Voltage; //Ch2 autoset voltage
WORD Ch1Timebase; //Ch1 autoset timebase
WORD Ch2Timebase; //Ch2 autoset timebase
WORD Ch1InGND; //Ch1 is in GND or not
WORD Ch2InGND; //Ch2 is in GND or not
WORD Ch1Enabled; //Ch1 enabled
WORD Ch2Enabled; //Ch2 enabled
};
struct TimeStruct{ //Save the time
double Timer; // the number of seconds elapsed since midnight
double Time; //the time of Timebase
double ScrollTime;
double ScrollStart;
};
Funct -
Hi, I purchased an USB based oscilloscope DSO-2150 from Hantek. Along with it came the VC++ DLLs (dll, lib and ocx). I need to create a Winform application using C# Visual Studio Express Edition. Please tell me is it possible to use VC++6 DLL in a C# appllication and if yes How? Following is scrap from the manual provided with the DLL files.
DSO-XXXX USB SDK Manual
SDKXXXX.dll (VC++ 6.0)
Define struct
struct PictureRange{ // Be used for draw grid
WORD width; // the width of display range
WORD height; // the height of display range
WORD left; //the left of display range
WORD right; //the right of display range
WORD top; //the top of display range
WORD bottom; //the bottom of display range
};
struct ControlStruct{ //save the control data
WORD TriggerSource; //the trigger source
WORD SelectedChannel; // the display channel
WORD Timebase; // timebase
WORD TriggerPosition; // the trigger vertical position “0%,25%,50%,75%,100%”
WORD DataLengh; // its value is 1 or 2, if BufferSize = 10, Datalengh = 1, else Datalengh =2
WORD BufferSize ; //Its value is 10,32 or 64
WORD isAlt; //If ALT trigger, its value is 1, else 0.
};
struct LeversStruct{ //save position
WORD Ch1Position; // the ch1 waveform horizontal position
WORD Ch2 Position; // the ch2 waveform horizontal position
WORD Ch1TriggerPosition; // the ch1 trigger position
WORD Ch2TriggerPosition; // the ch2 trigger position
WORD EXTTriggerPosition; // the EXT trigger position
};
struct StateStruct{
WORD Ch1Filt; // ch1 filter
WORD Ch2Filt; //ch2 filter
WORD TriggerFilt; // trigger filter
WORD TriggerMode; //trigger mode (AUTO, NORMAL, SINGLE)
WORD TriggerSlope; //trigger slope (rising edge, failing edge)
};
struct LineColor{ // the waveform color
WORD R;
WORD G;
WORD B;
};struct AutosetStruct{ //save the autoset data
WORD WhichChannel; //which channel will autoset
WORD Ch1Voltage; //Ch1 autoset voltage
WORD Ch2Voltage; //Ch2 autoset voltage
WORD Ch1Timebase; //Ch1 autoset timebase
WORD Ch2Timebase; //Ch2 autoset timebase
WORD Ch1InGND; //Ch1 is in GND or not
WORD Ch2InGND; //Ch2 is in GND or not
WORD Ch1Enabled; //Ch1 enabled
WORD Ch2Enabled; //Ch2 enabled
};
struct TimeStruct{ //Save the time
double Timer; // the number of seconds elapsed since midnight
double Time; //the time of Timebase
double ScrollTime;
double ScrollStart;
};
FunctHi, that seems doable, but it is not at a beginner's level. You will need a lot of P/Invoke. If you are not familiar with P/Invoke, I suggest: - you read up on it, both MSDN and some CodeProject articles; - you have a look at www.pinvoke.net[^] - you start with something simpler; I like to create my own native C coded DLL, using simple functions to test P/Invoke stuff. BTW: for the array stuff (where parameters are pointers) you either need to use the fixed and unsafe keywords, or the GCHandle class. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
Hi, that seems doable, but it is not at a beginner's level. You will need a lot of P/Invoke. If you are not familiar with P/Invoke, I suggest: - you read up on it, both MSDN and some CodeProject articles; - you have a look at www.pinvoke.net[^] - you start with something simpler; I like to create my own native C coded DLL, using simple functions to test P/Invoke stuff. BTW: for the array stuff (where parameters are pointers) you either need to use the fixed and unsafe keywords, or the GCHandle class. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
Hi Luc Thanks, It really seems tedious, need to learn lot to understand it. A friend of mine was suggesting adding a reference to dll and that will create a class for me to use directly. But he said I has not tried it anytime, what do you think is that possible. Thanks again, Regards, Karmendra
-
Hi Luc Thanks, It really seems tedious, need to learn lot to understand it. A friend of mine was suggesting adding a reference to dll and that will create a class for me to use directly. But he said I has not tried it anytime, what do you think is that possible. Thanks again, Regards, Karmendra
Hi, C# calling native code needs P/Invoke, AFAIK there is no way around that. Ask your friend for details of his method! :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
-
Hi, C# calling native code needs P/Invoke, AFAIK there is no way around that. Ask your friend for details of his method! :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!
Hi Luc, I just found i even have VB dlls does that help getting it done the easier way, I mean I don't mind learning new things, but don't have much time, but if their is no other go i will keep learning about accessing un-managed code in c# using pInvoke. Thanks a lot for your help, Regards, Karmendra Suthar
-
Hi Luc, I just found i even have VB dlls does that help getting it done the easier way, I mean I don't mind learning new things, but don't have much time, but if their is no other go i will keep learning about accessing un-managed code in c# using pInvoke. Thanks a lot for your help, Regards, Karmendra Suthar
Hi, if that is old VB stuff, it is still native code and C# needs P/Invoke. if that is managed VB.NET code, then it can be called directly, just instantiate the classes and operate on the properties and methods as if it too were C# code. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Love, happiness and fewer bugs for 2009!