Need Help on the combobox function

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Stlawance
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jun 24, 2011 2:02 am

Need Help on the combobox function

Post by Stlawance » Sat Jun 25, 2011 9:38 am

hello everyone,i am a new learner both in wxWidget and c++. i want to build a program. it can shows the number of sound card in the computer,their names and choose one as the default device. i also want the sound card to be shown in the combobox. here is the main code:

int i;
int j = waveInGetNumDevs();

int GetDeviceName()

{

int iIndex;
TCHAR *pName = (TCHAR *)malloc(50 * sizeof(TCHAR));

MMRESULT rc;
WAVEINCAPS inCaps;

rc = waveInGetDevCaps( iIndex, &inCaps, sizeof(inCaps));

if( rc == MMSYSERR_NOERROR )
{
strncpy_s( (char*)pName, MAXPNAMELEN, (const char*)inCaps.szPname, MAXPNAMELEN);
}

return *pName;
}


for (i=0; i < j; i++)
{
m_arrItems.Add( GetDeviceName() );
}

here is the error: error C2248: “wxString::wxString”: 无法访问 private 成员(在“wxString”类中声明)

Add is defined as this:
size_t Add(const wxString& str, size_t nInsert = 1);

can anyone tell me how to fix this litttttle bug ? I really need your help :( :( .

User avatar
doublemax
Moderator
Moderator
Posts: 13988
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Need Help on the combobox function

Post by doublemax » Sat Jun 25, 2011 12:50 pm

Code: Select all

int GetDeviceName()
{
[...]
return *pName;
}
GetDeviceName is defined to return an INT, there is no wxString ctor that takes an INT as argument.

Also be aware that the code as it is would leak memory as the buffer allocated with malloc will never get freed.
Use the source, Luke!

Stlawance
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Jun 24, 2011 2:02 am

Re: Need Help on the combobox function

Post by Stlawance » Mon Jun 27, 2011 8:53 am

Yeah,i have fixed it now. thanks :D

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Need Help on the combobox function

Post by Auria » Mon Jun 27, 2011 12:35 pm

If the question is solved, please mark the topic as closed by clicking on the green check button on top of the post that helped you most

Thanks
"Keyboard not detected. Press F1 to continue"
-- Windows

Post Reply