|
Hello,
Did anybody tried to store data (example: CString) in a DLL.
I just want to store some of my data in a DLL, and donot want to use any file to store that data.
Somone has ever did this or have any idea how to do this
Regards,
The Phantom
|
|
|
|
|
If I have handle to the window (HWND), how can I get the window title and the application's path using the win32 API functions.
|
|
|
|
|
//vollständigen Pfad ermitteln
char szPfad[ _MAX_PATH ];
VERIFY( ::GetModuleFileName( AfxGetInstanceHandle(), szPfad, _MAX_PATH ) );
Try this @ home. (B&B)
|
|
|
|
|
And for the window title, you can use this:
char Buffer[255];<br />
CWnd* pNewWnd = YourWindow->FromHandle(YourHandle)<br />
pNewXnd->GetWindowText(Buffer,254);
YourWindow is a CWnd (doesn't matter wich one). FromHandle returns the CWnd* attached to the Handle 'YourHandle'!
|
|
|
|
|
This has got to be the most irritating 'feature' of the windows API. not one problem has given me so much trouble, here is how my error catching goes:
[code]
int main(int argc, char ** argv)
{
try
{
CApp Instance;
return Instance.Run();
}
catch(ErrorInfo Error)
{
// build message here
MessageBox(NULL, Message, Title, MB_ICONERROR);
}
return 0;
}
[/code]
it works perfectly up to the .Create method of ATL's CWindowImpl. after that, DestroyWindow gets called, which seems to disable dialogs, which disables the message box. i've debugged it, it goes right over the call without displaying the window, but it does play the sound. is there any way to 'reset' windows before i show the message box?
|
|
|
|
|
Hi all,
can any one explain me what is the difference in the following code.
1.I have a class CSample.
2.I want to create an object on heap by using new operator for CSample.
I found there are two methods for this.
1.One is like this
CSample * pSamep=new CSample;
and
2.second one is like this
typedef auto_ptr<csample> pSample;
pSample(new CSample());
what is the difference with these two methods.which one is more efficient.
thanks in advance.
regards
raju
anju
|
|
|
|
|
anju wrote:
typedef auto_ptr pSample;
I assume you meant: typedef auto_ptr<CSample> pSample;
The auto_ptr is a small structure that holds the pointer to the object, and a flag indicating whether or not it owns the object (it does by default). In it's destructor, it deletes the object if it owns it. This can greatly simplify memory management, as these smart pointers take care of deleting themselves when they go out of scope.
In terms of efficiency, the auto_ptr would be every so slightly less efficient, but we are probably talking literally one or two CPU instructions, so it is really irrelevant.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
I have tried the follwing :
typedef auto_ptr<cstring> str;
but is not working. Gives error "syntax error : missing ';' before '<'".
Is any header file needed?
Chintan
C.R.Naik
|
|
|
|
|
I think it is in the <memory> header file, but it is also defined within the std namespace.
If you repost your error message, take not that codeproject thinks that everything between angle brackets is an HTML tag, and so does not display it. You should use < and >
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
previous time I have tried :
typedef auto_ptr < CString > str;
and again I have tried the following one :
typedef std::auto_ptr < CString > str;
but both are not working and giving error
Chintan
C.R.Naik
|
|
|
|
|
|
Both are unable to solve the problem.
C.R.Naik
|
|
|
|
|
I thought it might be useful to explain a little
more of the reason why auto_ptr was included in
the standard. (There was a great deal of haggling
about this and other types of pointer wrappers,
and there are a number of other pointer wrappers
in boost (boost.org) that will almost certainly
make it into the next version of the standard.)
The reason why auto_ptr is important relates to
exceptions. Consider this:
class excep { /* some exception class */};
void g()
{
try { f(); }
catch(excep &e)
{ handle(e); }
}
void f()
{
int* a = new int;
*a = might_throw_excep();
other_fn();
delete a;
};
Now consider what happens if might_throw_excep throws
an exception. In that case, the stack unwinds to
the nearest matching catch statement (in g), but that
means that a, which is now out of scope, points to
heap allocated memory that will never be deleted.
auto_ptr solves this problem, by rewriting f() as the
following:
void f()
{
auto_ptr<int> a = new int;
*a = might_throw_excep();
other_fn();
}
In this case, the destructor of a (which is an auto_ptr
template class) is called when it goes out of scope. This
causes the object a to be deleted. However, what is more
important is this: even if might_throw_excep throws, then
as part of the exception processing system, the destructors
of the classes are called as the stack is unwound to the
catch statement. This happens even though other_fn is not
called. That means that, even if an exception is
thrown, a's destructor is called, and it doesn't leak
memory.
For that reason, auto_ptr (or something like it) is
necessary to write leak free code in the presence of
exceptions. This is the motivation, AFAIK, behind why
auto_ptr was added to the standard.
HTH.
|
|
|
|
|
I am compiling something, however I get this error:
--------------------Configuration: encrypt - Win32 Debug--------------------<br />
Compiling...<br />
encrypt.cpp<br />
c:\program files\microsoft sdk\include\wincrypt.h(37) : error C2146: syntax error : missing ';' before identifier 'HRESULT'<br />
c:\program files\microsoft sdk\include\wincrypt.h(37) : fatal error C1004: unexpected end of file found<br />
Error executing cl.exe.<br />
<br />
encrypt.obj - 2 error(s), 0 warning(s)
and it takes me to this point in the wincrypt.h file (pointing at the red section):
#ifndef _HRESULT_DEFINED
#define _HRESULT_DEFINED
<font color="red">typedef LONG HRESULT;</font>
#endif // !_HRESULT_DEFINED
Does anyone have any clues?
-Nick Parker
|
|
|
|
|
are proper headers included before #include "wincrypt.h"? i think you should include "wtypes.h" in front of #include "wincrypt.h". or "stdafx.h" if your project has it
|
|
|
|
|
Zed wrote:
in front of #include "wincrypt.h". or "stdafx.h" if your project has it
Never ever include something in front of "stdafx.h"!
It is ignored after the preparation of the precompiled headers.
Either include in "stdafx.h" or after "stdafx.h".
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
yes, i know that.
what i meant was: include wtypes.h in front of wincrypt.h, or stdafx.h in front of wincrypt.h.
sorry for misunderstanding
|
|
|
|
|
That worked, thanks.
-Nick Parker
|
|
|
|
|
After converted the application from VC++ to .NET C++, I want to add a resource to the project. From the Project menu, I selected Add Resource. An error message popped up: error RC2135: file not found: MENU
I clicked OK and got another one: error RC2135: file not found: POPUP
What should I fix?
-Elizabeth
Eilzabeth
|
|
|
|
|
I have just converted an application from VC++6 to .NET C++. But I can not find the Dialog resource from the CDialog drived class in .NET. In VC++, I can get to the dialog resource from the Wizard Bar easily be scrolling down the member list. Where can I find it?
-Elizabeth
Eilzabeth
|
|
|
|
|
Hi I am trying to write data to the serial port using the windows api. I can write successfully by using a normal C style string with the MFC wrapper I wrote(with help from this site!) it goes something like this
void CSerComPort::WriteData(char* cData,DWORD dwBufferSize)
{
DWORD dwBytesWritten;
if(!WriteFile(m_ComPortHndl,cData,dwBufferSize,&dwBytesWritten,NULL))
; //throw exception for wrong write
else;// ASSERT(dwBytesWritten == sizeof(dwData));
}
works fine when i declare something like
char dwdata[]="test string";
But Ideally i would like to read data in from an edit box and this variable is of type CString, I have tried to use the member function GetBuffer which seems to be ok but when I pass GetLength as the second parameter it says I can't convert between int and unsigned long. Is there a standard way to do this, or would I be better rewriting the WriteData function? Please bear with me I am quite new to windows programming but I would like to know if there is a standard way to achieve this. Thanks
Andy
|
|
|
|
|
// I am asuming no UNICODE is involved.
// This should work, since LPTSTR is defined as char*
CString csData;
GetDlgItemText(IDC_TEXTSTRING, csData);
WriteData( LPCTSTR(csData),(DWORD)csData.GetLength() );
// Here are some more options
// If using C
char szBuffer[512];
int nLen = GetDlgItemText(hDlg, IDC_TEXTSTRING, szBuffer, sizeof(szBuffer));
WriteData( szBuffer,(DWORD)nLen );
// If using MFC
int nLen = GetDlgItemText(IDC_TEXTSTRING, szBuffer, sizeof(szBuffer));
WriteData( szBuffer,(DWORD)nLen );
// Else If using MFCs CString
CString csData;
GetDlgItemText(IDC_TEXTSTRING, csData);
// Then
WriteData( LPCTSTR(csData),(DWORD)csData.GetLength() );
// or
const char* pszData = csData.GetBuffer(csData.GetLength());
WriteData( pszData ,(DWORD)csData.GetLength() );
csData.ReleaseBuffer();
// or
WriteData( csData.LockBuffer(),(DWORD)csData.GetLength() );
csData.UnlockBuffer();
Trust in the code Luke. Yea right!
|
|
|
|
|
Conversion from CString to char* is simple.
For example,
CString str = "test string;
then you should write
WriteFile(m_ComPortHndl,(char*)(LPCTSTR) str, str.GetLength(), &dwBytesWritten,NULL)
C.R.Naik
|
|
|
|
|
|
Thanks for the help guys, I appreciate it
Andy
|
|
|
|