PDA

View Full Version : Help---- VC# to VC++ .Net --- Help


bxchan
11-05-2006, 05:40 PM
Hi, i am newbie on VC++ .Net.
i face a problem to convert VC# code to VC++ .Net
--------------------------------------------------------------------------
here is VC# code (Working)
--------------------------------------------------------------------------
class Class1
{
[DllImport("setupapi.dll")]//
public static extern Boolean
SetupDiClassGuidsFromNameA(string ClassN, ref Guid guids, UInt32 ClassNameSize, ref UInt32 ReqSize);

[STAThread]
static void Main(string[] args)
{
UInt32 RequiredSize = 0;
Guid[] guids=new Guid[1];

bool res=SetupDiClassGuidsFromNameA("DiskDrive",ref guids[0],RequiredSize, ref RequiredSize);
}

--------------------------------------------------------------------------
Here is the code that i convert to VC++(no working)
--------------------------------------------------------------------------

#include "stdafx.h"

#using <mscorlib.dll>
using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Text;

[DllImportAttribute("setupapi.dll", CharSet=CharSet::Auto)]
extern "C" Boolean
SetupDiClassGuidsFromNameA(String *ClassN, Guid* guids, UInt32 ClassNameSize, unsigned int *ReqSize);

int _tmain()
{
UInt32 RequiredSize = 0;
Guid guids = new Guid[1];
SetupDiClassGuidsFromNameA(S"DiskDrive", guids[0], RequiredSize, &RequiredSize);
Console::WriteLine(RequiredSize.ToString());
return 0;
}
--------------------------------------------------------------------------The Correct behaviour is the RequiredSize should be Greater than 0, but the code that i have convert the RequiredSize always return 0.:wallbash:

can any one help me.

Thank you.

Regards,
bxchan

Skavenger
11-28-2006, 02:50 AM
Because the 3rd parameter your passing into SetupDiClassGuidsFromNameA()
should be the "ClassGuidListSize" your passing in 0.

- Skavenger.