|
This is how I did it
BOOL CModelessDialog::PreTranslateMessage(MSG* pMsg)
{
switch ( pMsg->message )
{
case WM_SYSKEYDOWN:
if ( ( pMsg->wParam >= 'A') && ( pMsg->wParam <= 'Z'))
{
AfxGetMainWnd()->SetFocus();
return false;
}
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
|
|
|
|
|
i am trying to give my XML parsing code UNICODE support. if UNICODE is not defined it works fine. but if i define it it gives some garbage values. (i am showing it in mag box) the problem is in the
dwFileRead = static_cast<dword>(fread(ptempXML, sizeof(TCHAR), dwFileSize, pfTempXMLBuf));
statement. what are the changes i have to make in the code. the file successfully comes in pfTempXMLBuf. but ptempXML shows garbage.
pfTempXMLBuf = _tfopen(tcsBufXMLFileName, _T("w+"));
m_pNode->Print(pfTempXMLBuf, 0);
fseek(pfTempXMLBuf,0, SEEK_SET);
dwFileSize = _filelength(fileno(pfTempXMLBuf ));
ptempXML = new TCHAR[dwFileSize + 1];
if(ptempXML)
{
memset(ptempXML, 0, dwFileSize); // Required otherwise ending char are junk.
fseek(pfTempXMLBuf,0, SEEK_SET);
dwFileRead = static_cast<dword>(fread(ptempXML, sizeof(TCHAR), dwFileSize, pfTempXMLBuf));
ptempXML[dwFileRead] = _T('\0'); // Required as the file size is most larger then the actual file contain read which appends junk at end.
rc = ptempXML;
delete []ptempXML;
}
|
|
|
|
|
|
sandeepkavade wrote: but if i define it it gives some garbage values.
How are you verifying this?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
I'm currently trying to get an n-ary tree implemented in C (I know, C++ would be so much better, but I'm stuck with it). Each node is a struct, which holds a pointer to a string, which is assigned whilst the node is being setup. Basically, I'm confused over the use of malloc and free; I don't think everything is being correctly freed at the moment.
Struct:
typedef struct node {
char *sData;
int iNumChildren;
struct node *nParent;
struct node *nChildren[MAX_NODES];
} treeNode;
addNode:
struct node* addNode(struct node *nParent, char *sData)
{
treeNode *temp;
int iNodeLevel;
if( nParent->iNumChildren < MAX_NODES )
{
temp = malloc( sizeof( treeNode ) );
temp->sData = sData;
...
return temp;
}
else
{
return NULL;
}
}
freeTree:
void freeTree()
{
int iRep;
int iFreed = 0;
char *sData;
treeNode *temp;
while( getNumChildren( root ) > 0 )
{
temp = root->nChildren[ root->iNumChildren - 1 ];
for( iRep = 0; iRep < iLongestPath; iRep++ )
{
if( getNumChildren( temp ) > 0 )
temp = temp->nChildren[ temp->iNumChildren - 1 ];
}
temp->nParent->iNumChildren--;
sData = temp->sData;
free( temp );
iFreed++;
printf( sData );
}
free(root);
iFreed++;
#ifdef _DEBUG
printf( "Freed %d nodes\n", iFreed );
#endif
}
As you can see, I've put in some code to check if the string was being freed, and it's not. However, I don't know how else this could be done; I'm not exactly a C guru.
Also, I did have a look around to see if there was anything similar, but all the code I found was in C++, which is no good for me. If anyone knows of something I could look at, I'd be supremely grateful.
Any ideas?
Sean.
|
|
|
|
|
The big question is how you call addNode and especially if sData has been allocated by alloc or do you call it like this addNode(pParent,"newNode")!
Because your freeNode frees the data, I think your addnode should allocate it as well... so I would rewrite it like this
in your addNode
temp->sData = sData;
temp->sData = malloc(strlen(sdata)+1);
strcpy(temp->sData,sdata);
Hoping this helps!
|
|
|
|
|
I did what you said, and it finally works! Not sure what I was doing wrong before, but thanks!
|
|
|
|
|
DarkWeaver5455 wrote: temp->sData = sData;
Has sData been malloc'd prior to calling addNode() ?
DarkWeaver5455 wrote: // This didn't work
Which means what exactly?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Whilst testing the functions, I was passing string literals in, which may be the problem.
Thinking about it now, because I technially didn't use malloc to allocate the memory for the strings (just passed in a lateral), I expect I can't use free to free the memory. Related to this, is the memory used by the string literals guaranteed to stay the same? And will it be freed when I close the app, or is there some way to free it whilst running?
|
|
|
|
|
DarkWeaver5455 wrote: Related to this, is the memory used by the string literals guaranteed to stay the same?
Yes.
DarkWeaver5455 wrote: And will it be freed when I close the app...
Yes.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for the speedy response, glad I have that sorted now!
|
|
|
|
|
how to add gif image to button
|
|
|
|
|
You can try like this
CImage m_Image;
m_Image.Load(filename);
m_Button.SetBitmap(m_Image.Detach());
|
|
|
|
|
CImage' : undeclared identifier what is a problem
#include <afxcmn.h>
#include <afxstr.h>
#include <atlimage.h>
I have the added these header files but
afxstr.h no such file or directroy
|
|
|
|
|
I dont know you include this file or no AtlImage.h
|
|
|
|
|
|
hi all
this is the code to fetch data from mysql using vc++
but my problem is that data is not shown in info which i declare as cstring as
mysql return data in string
evrything is ok
but data is not shown in info variable please help me
GetDlgItemText(IDC_EDIT1,f);
info = select ID from login where name = \'" + f + "\'";
if ( ! mysql_query( myDB, info) )
{
res = mysql_store_result( myDB );
row = mysql_fetch_row( res );
}
thanks
hi
|
|
|
|
|
Hi to all
i want to make a windows service using the wxwidget but i not getting thru i found the following http://danny.ronyao.com/modules/newbb/rss.php?f=17[^]
but i not getting thru compiling it does anyone know how to do it or does anybody have it compiled that could e-mail it to me?
|
|
|
|
|
seneralex wrote: but i not getting thru compiling it does anyone know how to do it or does anybody have it compiled that could e-mail it to me?
better ask it in wxwidget forums...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
|
Hi,
I require a basic reporting tool having capabilites to display charts. Any idea?
-Piyush
|
|
|
|
|
|
Do send a link when you find the cart-wheeling green eyed blond!
re reporting, one can also us Crystal Reports COM objects - the designer is not free, I think the rest is distributable...
|
|
|
|
|
Hi all,
I has been created one MFC extension dll called SRecordset.dll,which has been one .h file and one .cpp file
my dll .h file..
#pragma once<br />
#include afxdb.h<br />
<br />
<br />
class AFX_EXT_CLASS SRecordset : public CObject<br />
{<br />
DECLARE_SERIAL(SRecordset)<br />
<br />
<br />
public:<br />
SRecordset(void);<br />
<br />
public:<br />
~SRecordset(void);<br />
<br />
protected:<br />
CStringArray saDataContainer;<br />
short iNumFldCount;<br />
long iNumRec;<br />
int iRecCount;<br />
int iTotalSize;<br />
int iRecordState;<br />
int iLocalIndex;<br />
public:<br />
BOOL SSOpen(CDatabase &dbConnectedObj,CString sQuery);<br />
BOOL SSIsOpen(void);<br />
void SSClose(void);<br />
public:<br />
BOOL SSIsBOF(void);<br />
BOOL SSIsEOF(void);<br />
public:<br />
void SSGetFieldValue(int iIndex,CString &FldValue);<br />
short SSGetFieldCount(void);<br />
long SSGetRecordCount(void);<br />
long SSGetCurrentRecordCount(void);<br />
public:<br />
void SSMoveNext(void);<br />
void SSMovePrevious(void);<br />
void SSMoveFirst(void);<br />
void SSMoveLast(void);<br />
public:<br />
virtual void Serialize(CArchive& ar);<br />
};
I has been created my dll successfully. But, it won't support to the client application,it will be thrown only one linker error, when i call rather the SSOpen(CDatabase &dbConnectedObj,CString sQuery) function only, not other function calls from my above the class during the runtime.
Here the part of code from my client app...
void CtestingDlg::OnBnClickedOk()<br />
{<br />
<br />
<br />
CDatabase db;<br />
CString sIp,sDb,sPwd,sConn,sPort,sUn;<br />
sIp="192.168.2.17";<br />
sPort="5432";<br />
sPwd="fasp";<br />
<br />
<br />
try<br />
{<br />
sConn = "DRIVER={PostgreSQL ANSI};SERVER=" + sIp + ";port=" +<br />
sPort + ";DATABASE=" + sPwd + ";UID=" + sPwd + "WD=" + sPwd + ";";<br />
db.OpenEx(sConn);<br />
AfxMessageBox("Success");<br />
}<br />
catch(CDBException *e)<br />
{<br />
MessageBox("Database Connection Refused."+e->m_strError,"DataBase<br />
Connection Error",MB_OK|MB_ICONERROR);<br />
e->Delete();<br />
<br />
}<br />
<br />
<br />
SRecordset set1;<br />
<br />
set1.SSOpen(db,"select name from master;");<br />
set1.SSGetFieldCount();<br />
set1.SSGetRecordCount();<br />
set1.SSClose();<br />
<br />
OnOK();<br />
}
where set1.SSOpen(db,"select name from master;"); is the problem
Error is.....
testingDlg.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: int __thiscall SRecordset::SSOpen(class CDatabase &,class ATL::CStringT > >)" (__imp_?SSOpen@SRecordset@@QAEHAAVCDatabase@@V?$CStringT@DV?$StrTraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@@Z) referenced in function __catch$?OnBnClickedOk@CtestingDlg@@QAEXXZ$0
please note that my class is derived from CObject class meanwhile CDatabase is also derived from CObject class...i think may be this is the reason for my problem?
please help me!
|
|
|
|
|
Did you provide a body for this function ?
|
|
|
|