|
Hey eveybody,
I have written a WndProc() function that detects the insert and removal of a USB drive and
want to pull out the specific LParam values to get the name of the drive and other info.
The examples I've found so far use a particular C# code that goes like this...
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public struct DEV_BROADCAST_VOLUME<br />
{<br />
public int dbcv_size;<br />
public int dbcv_devicetype;<br />
public int dbcv_reserved;<br />
public int dbcv_unitmask;<br />
}<br />
protected override void WndProc(ref Message m)<br />
{<br />
const int WM_DEVICECHANGE = 0x0219;<br />
const int DBT_DEVICEARRIVAL = 0x8000;
const int DBT_DEVTYP_VOLUME = 0x00000002;
if (m.Msg == WM_DEVICECHANGE && m.WParam.ToInt32() == DBT_DEVICEARRIVAL)<br />
{<br />
int devType = Marshal.ReadInt32(m.LParam,4);<br />
if(devType == DBT_DEVTYP_VOLUME)<br />
{<br />
DEV_BROADCAST_VOLUME vol;<br />
vol = (DEV_BROADCAST_VOLUME) Marshal.PtrToStructure(m.LParam,typeof(DEV_BROADCAST_VOLUME));<br />
MessageBox.Show(vol.dbcv_unitmask.ToString("x"));<br />
}<br />
}<br />
base.WndProc (ref m);<br />
}<br />
And I've been trying to get the LParam into my structure like this:
<br />
__gc struct Volume<br />
{<br />
int size;<br />
int devicetype;<br />
int reserved;<br />
int unitmask;<br />
}<br />
<br />
protected: void WndProc(System::Windows::Forms::Message* message) <br />
{<br />
...<br />
if(message->Msg == WM_DEVICECHANGE)<br />
{<br />
if(message->WParam == DBT_DEVICEARRIVAL)<br />
{<br />
lVolume = (Volume*)Marshal::PtrToStructure(message->LParam,__typeof(Volume));<br />
<br />
String* str = MaskToLogicalPaths(lVolume->Mask);<br />
this->m_FoundBox->Text = String::Format("Plugged In: {0}",str);<br />
}<br />
else <br />
if(message->WParam == DBT_DEVICEREMOVECOMPLETE)<br />
{<br />
this->m_FoundBox->Text = String::Format("UnPlugged: {0}",message->WParam.ToString());<br />
} <br />
}<br />
}<br />
This continues to not work in MC++.
For some reason I cannot find a viable alternative to the C# code in MC++. My errors include
the dreaded run-time:
"The specified structure must be blittable or have layout information..."
among other more standard compile errors for instantiating the structure incorrectly.
I know theres a way to do this but havent found it yet.
Any help you all could be would be greatly appreciated!
ScottLeff
sleff@yahoo.com
|
|
|
|
|
How to apply "Force file output" option in Visual Studio.NET i.e. VC7. In Visual Studio 6.0, it is available in "Link-->Customize" option in Project Settings of VC++ project.
Can any one help me out please
|
|
|
|
|
Hi All,
In C++/CLI I have used a 2 Dimensional String Array.
My code:
array<String^,2> ^strarr=gcnew array<String^,2>(2,2){"focus1","focus2","focus3","focus4",};
and when I want a string to print on console
ie
Console::Writeline("{0}",strarr[0][0]);
compiler is giving Error.
can any one suggest
Bye..
G.Nagaraju
|
|
|
|
|
Hi,
if want to directly initialize your array then you'll have to do it like this:
<code>
array<String^,2>^ strarr = gcnew array<String^,2>{{"focus1","focus2"},{"focus3","focus4"}};
Console::WriteLine("{0}",strarr[0,0]);</code> In additon I would recommend you to read this article.
http://www.codeproject.com/managedcpp/cppcliarrays.asp[^]
best regards Tobias
|
|
|
|
|
hi.I am using visual studio .net 2003 and I am new to managed c++.
I have to write joystick controller(mouse stick)but I dont now where to start.
|
|
|
|
|
What do you mean by a joystick controller? To me the hardware is the controller and the software is the driver and your program communicates with this driver by an api.
I assume you need to have your program use the joystick support that is built in the operating system? DirectInput (part of directx) has support for joysticks.
John
|
|
|
|
|
I have to create a GUI which control the camera.in my GUI i need to create a mouse stick which controls the camera like rotate left or right. but i get stuck on the mouse stick.In order to create this mouse stick where should i start.
|
|
|
|
|
|
thank you very much for the article.I almost finish qui part of my project
Mert Aydin
|
|
|
|
|
Hey guys, I am trying to understand some codes and came across this.
In the code below, I don't know if its a pointer to RTIambassador object. I don't see why there is RTI:: in front of RTIambassador* and also ms_rtiAmb is not a method of class ObjectRoot. I don't see why they have ObjectRoot:: in front of ms_rtiAmb.
Thanks,
Jay
RTI::RTIambassador* ObjectRoot::ms_rtiAmb = NULL;
|
|
|
|
|
don't cross post the forums
we already answered you on the other board... can't you just wait for an answer more than 5 minutes ??
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
|
|
|
|
|
|
Hi,
I've got an application that uses mixed C++.
Sometimes, the application crashes with AccessViolationException
It seems that the cause is that I'm using unmanaged pointers without pinning.
Here is the code that crashes sometimes
<br />
__gc class CRichTextBuffer<br />
{<br />
public:<br />
CRichTextBuffer()<br />
{<br />
m_BufferSize = 32;<br />
m_BufferPosition = 0;<br />
m_buf = new char[m_BufferSize];<br />
}<br />
<br />
public:<br />
bool CreateCDParagraph(CDPABDEFINITION __gc *Definition)<br />
{<br />
Int32 nSize;<br />
bool bResult = false;<br />
int nStep = 0;<br />
<br />
try<br />
{<br />
nSize = ODSLength(_CDPABDEFINITION); nStep++;<br />
<br />
<br />
if ( CheckSize(nSize) ) <br />
{<br />
LPTSTR LPStrResult = new TCHAR[nSize]; nStep++;<br />
LPTSTR LPStrTmp = LPStrResult;
nStep++;<br />
<br />
CDPABDEFINITION Def;<br />
CopyStructure( &Def, Definition ); nStep++;<br />
<br />
ODSWriteMemory( &LPStrTmp, 10, &Def, 1 ); nStep++;<br />
<br />
CopyMemoryInBuffer(LPStrResult, nSize); nStep++;<br />
delete [] LPStrResult; nStep++;<br />
<br />
bResult = true;<br />
}<br />
}<br />
catch (Exception* e)<br />
{<br />
String *sMsg = String::Concat("Exception: ", e->get_Message()," - Step=", nStep.ToString());<br />
System::Diagnostics::Debug::Assert(false, sMsg);<br />
bResult = false;<br />
}<br />
<br />
return bResult;<br />
}<br />
<br />
protected:<br />
char *m_buf;<br />
int m_BufferPosition;<br />
int m_BufferSize;<br />
}<br />
I'm new with __pin pointers
where is the problem? where need I use __pin pointers?
I know that I can't __pin the class member m_buf. How can I prevent the application from crash?
Thanks in advance for your help
Stf
|
|
|
|
|
I've got an unmanaged C++ library which I've now compiled as a managed assembly (changed the output type etc.) When I try to use this in another Managed C++ project, I get C2871 - a namespace with this name does not exist. I have tried using both:
#using (with the Resolve #using references setting)
Adding a reference (automatic /FU switch)
but neither works; I still get C2871 on the first "using namespace" line.
The really strange thing is that I have built a test c# application and this is able to use the assembly just fine!
Any clues anyone?
Mark
|
|
|
|
|
if u r sure that u can use the assembly from C#, no doubt u should be able to use the same from managed cpp as well.
To confirm the namesapce/class names u used in managed cpp:
* chk it in c#, by press ctrl+alt+j and see the namespace details in the object browser.
* or use ildasm.exe to di assemble the assembly and see the namespace type informations.
cheers...milton kb
|
|
|
|
|
Thanks for the advice. The strange thing is, I've already checked this.
ildasm.exe shows the namespace just as I'm trying to use it and C# uses it without a problem. The Managed C++ compiler picks up the dll from the #using statement but can't seem to find the namespace in a subsequent "using namespace ..." statement.
I've tried using a different dll in the project and this works OK. I've also tried compiling the included dll in a complete new project - same problem. So it seems to be something wrong with this particular dll. I just don't understand how the C# compiler can see the namespace whereas the C++ one can't.
Ideally I want to get the C++ compiler to verbosely tell me exactly what it's searching and what it 'sees'. I guess that's not possible!
Mark.
|
|
|
|
|
hello,
I want to create a managed C++ dll to access a .net component.
The managed C++ dll is used in a plain C++ application.
Is this possible?
greetings,
Niko
|
|
|
|
|
For accessing a .net component from palin c++(unmanaged)you have to use CCW com callable wrapper.
For this, if the .net component is already written in such a way that it be used for generating the ccw, directly use it. or else write a managed c++/c# wrapper which is compliant with requirements fo a CCW. then use the ccw from plain c++
cheers...milton kb
|
|
|
|
|
Hi,
As I mentioned in the subject line, I am an experienced C programmer. I want to upgrade myself to a C++ programmer. I am a little bit familiar with Object Oriented Programming concepts, so I believe myself to overcome this transition from C to C++, but I need your proper directions to my this aim. In order to appropriately achieve this, could you send your directions and suugestions?
Thank you in advance.
Semih
|
|
|
|
|
I usually grab a good book. Go though the book and do some exercises. As you are familiar with C syntax and some OOP, the learning curve shouldn't be steep for you.
If you want to develop on .NET, after you gain a fair grasp of Standard C++, find a recent book that teaches C++/CLI extensions. Don't jump on C++/CLI before you know Standard C++.
Best,
Jun
|
|
|
|
|
Thank you for your suggestions, which compiler environment should I prefer to develop my codes in C++? This compiler environment is surely helpful to implement and interesting to increase work desire.
Best regards,
Semih
|
|
|
|
|
sergin80 wrote: which compiler environment should I prefer to develop my codes in C++?
C/C++ uses the same compiler. I recommend Visual C++ and GCC.
sergin80 wrote: This compiler environment is surely helpful to implement and interesting to increase work desire.
True. In this regard, VC++ probably motivates the learning process more.
Best,
Jun
|
|
|
|
|
sergin80 wrote: In order to appropriately achieve this, could you send your directions and suugestions?
I highly recommend Accelerated C++[^] as a standard C++ introductionary text.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
I'm working with the XmlTextReader and I'm having some difficulty navigating through the xml document. The issue I'm running into is getting the attributes from the child nodes of a specific element. Here is a sample layout of the xml document.
<sample>
<hw id="HP-D500" name="Compaq Evo D500 Desktop" type="Desktop">
<software fn="SP26150.exe" title="HP Easy Access Keyboard Driver for Windows 2000/XP" type="DRIVER"
category="Input Devices" version="8.0.0.683" path="OS\ID\HP\KB" si="setup.exe -s"></software>
</hw>
<hw id="HP-D510" name="Compaq Evo D510 Small Form Factor" type="Desktop">
<software fn="SP26150.exe" title="HP Easy Access Keyboard Driver for Windows 2000/XP" type="DRIVER"
category="Input Devices" version="8.0.0.683" path="OS\ID\HP\KB" si="setup.exe -s"></software>
</hw>
<hw id="HP-N600c" name="Compaq Evo n600c Notebook PC" type="Laptop">
<software fn="SP22515.exe" title="Easy Access Buttons" type="Application"
category="Input Devices" version="3.00" path="OS\ID\SP22515" si="setup -s -SMS"></software>
<software fn="SP27852.exe" title="HP Notebook LidSwitch Policy" type="DRIVER"
category="OS and OS Enhancements" version="2.02" path="OS\Enh\SP27852" si="setup.exe -s"></software>
<software fn="SP21661.exe" title="Synaptics Touchpad Driver for Windows 2000 and XP" type="DRIVER"
category="Input Devices" version="6x" path="OS\ID\SP21661" si="setup.exe -s -SMS"></software>
<software fn="SP22442.exe" title="Compaq Hotkey Support Software" type="Application"
category="OS and OS Enhancements" version="1.1" path="OS\Enh\SP22442" si="\disk1\setup.exe -s -SMS"></software>
</hw>
</sample>
Here is the function implementation that is parsing the file.
StringCollection* ESBPARSER::getModelSoftware(XmlTextReader* Reader,String* modelName)
{ //modelName contains the attribute from a hw element name id.
StringCollection* SOFTWARE_LIST = new StringCollection();
try {
while (Reader->Read())
{
if (Reader->NodeType == XmlNodeType::Element)
{
if (Reader->HasAttributes)
{
Reader->MoveToAttribute("name");
int strVal = Reader->Value->ToString()->CompareTo(modelName);
if (strVal == 0)
{
// Logic to Get each Child element attribute name title
}
}
}
}
}
catch(...){
MessageBox::Show(S"An Error has occurred while trying updating hardware list box.");
}
return SOFTWARE_LIST;
}
Any help would be greatly appreciated.
TIA
|
|
|
|
|
Is it possible to use C++/CLI for Mobile Device, PPC 2003 /2005
thank
|
|
|
|