|
woops.. the includes are:
#include "winsock.h"
#include "iostream.h"
|
|
|
|
|
Hi, i'm currious,
I'm writing a winnt service application.
So I start of with a basic win32 console application.
There is not a CWinApp in the main file just the _tmain function.
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
Then I remembered that i need some MFC classes or at least the support for it.
I recreate the project, but now i check out the option to include standard MCF headers.
Now i get:
<code>CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
}
return nRetCode;
}</code>
Why is this? The CWinApp object theApp is never used. What does it do?
Any insights would be appreciated.
Learn from the mistakes of others, you may not live long enough to make them all yourself.
|
|
|
|
|
BadKarma wrote: The CWinApp object theApp is never used
Not strictly true. It's a global variable, which means its constructor will be called before _tmain is executed. CWinApp::CWinApp does a whole load of MFC initialisations for you, that will then be used by other MFC functions that you call (or are called for you by the framework).
|
|
|
|
|
BadKarma wrote: if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
BadKarma wrote: Why is this? The CWinApp object theApp is never used. What does it do?
Look up CWinApp constructor and then step into AfxWinInit , you will see that it needs a CWinApp object, see the call AfxGetApp() . AfxGetApp is able to get an application pointer due the following line in the CWinApp constructor.
pModuleState->m_pCurrentWinApp = this;
Some MFC specific initialization is also done in these functions and stored in thread local storage. This happens in AfxTls.cpp line number 100, comes via AfxClassInit().
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
modified on Thursday, June 12, 2008 8:51 AM
|
|
|
|
|
dear all
sorry to disturb you by this problem, but i really couldn't solve it.
when i install vc++ 2008, first install .net framework 3.5,in the way to install it, aborted, it showed me it encountered problem, couldn't install. what is problem? anyone can remind me.thanks a lot.
gentleguy
|
|
|
|
|
Sorry my Code Project Mind Reader Unit is out of order today.
BTW what was the error message shown?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Dear!
If your problem is similar to
http://groups.google.com/group/microsoft.public.dotnet.framework/browse_thread/thread/dfd37eb8a077e9f0?hl=en#
http://forums.msdn.microsoft.com/en-US/netfxsetup/threads/ ( search for 1603 error in installation of WPF in google)
These two threads were started by me and the only option is to either format your PC and install VS 2008 before installing anything else or call microsoft support service.
If you still want to give a try, then this is the first and last place to visit -
http://blogs.msdn.com/astebner/archive/2008/03/28/8342307.aspx
write to aaron stebner if his blog does not help. he may help you.
Good luck and do tell us whether you were able to solve your problem and how!
|
|
|
|
|
You can try:
Uninstall all previous .NET 3.5 framework installs
Make sure there's no previous Visual Studio 2008 versions installed
Install .NET Framework 3.5[^]
Install Visual Studio 2008
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You forgot format C:
led mike
|
|
|
|
|
Hi guys i am new in MFC i want to know how to search for a specific file and delete it. ?? So please help me. I didn't find any any function for deleting like rename(brfore,after) for renaming a file or folder name.
Regards:
Xohaib Shirani
|
|
|
|
|
Use FindFirstFile()/FindFirstFileEx() to find a file with a specifc name. DeleteFile() to delete it
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
If you already know the path of the file to be deleted, then you don't have to search for it. You can use PathFileExists() function to see if the file exists. you can also use the function PathIsDirectory() to see if given path is that of a directory or a file. The below code snippet might make the point clear to you.
TCHAR szFilePath[MAX_PATH];
_tcscpy(szFilePath, _T("C:\\file.txt") );
if(PathFileExists(szFilePath) && !PathIsDirectory(szFilePath))
DeleteFile(szFilePath);
Regards,
Vijay.
|
|
|
|
|
error C2065: 'PathFileExists' : undeclared identifier
error C2065: 'PathIsDirectory' : undeclared identifier
Regards:
Xohaib Shirani
|
|
|
|
|
Header shlwapi.h
Import library shlwapi.lib
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
Hi
In Programming with Microsoft Visual C++.NET book, author shows a custom control dll. In his code:
LRESULT CALLBACK AFX_EXPORT
RygWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd* pWnd;
pWnd = CWnd::FromHandlePermanent(hWnd);
if (pWnd == NULL) {
pWnd = new CRygWnd();
pWnd->Attach(hWnd);
}
ASSERT(pWnd->m_hWnd == hWnd);
ASSERT(pWnd == CWnd::FromHandlePermanent(hWnd));
LRESULT lResult = AfxCallWndProc(pWnd, hWnd, message,
wParam, lParam);
return lResult;
}
I downloaded The Ultimate Toolbox code, there is no call to AfxCallWndProc
For example:
BOOL COXTabViewContainer::Create(CWnd* pParentWnd, CRect rect,
DWORD dwStyle,
UINT nID)
{
ASSERT(pParentWnd != NULL);
ASSERT(dwStyle & WS_CHILD);
ASSERT(nID != 0);
DWORD dwCreateStyle=dwStyle&~(WS_HSCROLL|WS_VSCROLL);
dwCreateStyle&=~WS_BORDER;
dwCreateStyle|=WS_CHILD;
WNDCLASS wndClass;
wndClass.style=CS_DBLCLKS;
wndClass.lpfnWndProc=AfxWndProc;
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hInstance=AfxGetInstanceHandle();
wndClass.hIcon=0;
wndClass.hCursor=::LoadCursor(NULL,IDC_ARROW);
wndClass.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
wndClass.lpszMenuName=NULL;
wndClass.lpszClassName=_T("TabViewContainer");
if(!AfxRegisterClass(&wndClass))
return FALSE;
if (!CreateEx(WS_EX_CLIENTEDGE,wndClass.lpszClassName,NULL,
dwCreateStyle,rect.left,rect.top,rect.Width(),rect.Height(),
pParentWnd->m_hWnd,(HMENU)(INT_PTR)nID,NULL))
{
return FALSE;
}
pParentWnd->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_DRAWFRAME);
::SetWindowLongPtr(GetSafeHwnd(),GWL_USERDATA,ID_TABVIEWCONTAINER_SIGN);
SetScrollStyle(0,TRUE);
CalcLayout();
return TRUE;
}
In MSJ for AfxCallWndProc:
You can think of AfxWndProc as a function with a big switch statement that routes WM_XXX messages to your window class's OnXXX handler functions. This is a first-order approximation of how AfxWndProc works:
// This is a gross simplification
LRESULT AfxWndProc(HWND hwnd, UINT msg, ...)
{
CWnd* pWnd = CWnd::FromHandle(hwnd);
switch (msg) {
case WM_CREATE:
pWnd->OnCreate(...);
return 0;
case WM_SETFOCUS:
pWnd->OnSetFocus(...);
return 0;
.
.
.
// etc.
}
return 0L;
}
If AfxWndProc routes WM_XXX messages to window class's OnXXX handler functions, why didn't Ultimate toolbox use it?
If i derive a class from any MFC wnd class(CWnd, CFrameWnd, CEdit etc...) haven't it got all the default wndproc for messages(because i derived it from CWnd class)? So why do we need to call AfxWndProc?
|
|
|
|
|
I have this code snippet which writes an encrypted value of a string into a file
(KEY_FILE -- #defined as C:\xyz.txt) ;
BYTE *pbBlob;
DWORD cbBlob;
:
:
:
if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, NULL, &amp;cbBlob))
{
dwResult = GetLastError();
MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
return;
}
if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, NULL, &amp;cbBlob))
{
dwResult = GetLastError();
MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
return;
}
if ((pbBlob = (BYTE *) LocalAlloc(LMEM_ZEROINIT,cbBlob)) == NULL)
{
dwResult = ERROR_NOT_ENOUGH_MEMORY;
MessageBox("Error LocalAlloc() failed.", "Information", MB_OK);
return;
}
if (!CryptExportKey(hSessionKey, hKey, SIMPLEBLOB, 0, pbBlob, &amp;cbBlob))
{
dwResult = GetLastError();
MessageBox("Error CryptExportKey() failed.", "Information", MB_OK);
return;
}
if(hSessionKey != 0)
CryptDestroyKey(hSessionKey);
hSessionKey = 0;
FILE *fp = fopen(KEY_FILE, "w+b");
if (fp) {
fwrite(pbBlob, 1, cbBlob, fp);
fclose(fp);
}
I find a junk value written by the above code in "C:\xyz.txt" which is like :
h ¤ zÛ³Wp &amp;lt;ø®lŒoWP¸"Ç^1iM€ÌygUjŽæ#Eì}ÔKËëü’²ôâ&amp;nbsp; äÃr[X&amp;gt;¾U
Since, the file contained
h ¤ zÛ³Wp &amp;lt;ø®lŒoWP¸"Ç^1iM€ÌygUjŽæ#Eì}ÔKËëü’²ôâ&amp;nbsp; äÃr[X&amp;gt;¾U string,
I was expecting pbBlob to point to the above content ie.
h ¤ zÛ³Wp &amp;lt;ø®lŒoWP¸"Ç^1iM€ÌygUjŽæ#Eì}ÔKËëü’²ôâ&amp;nbsp; äÃr[X&amp;gt;¾U
But when I debug, the following line
fwrite(pbBlob, 1, cbBlob, fp)
shows me the value of pbBlob = "||" and cbBlob = 76
What is the problem here. How can I get the junk value in a CString ?
Will some kind of casting help ?
|
|
|
|
|
Go to memory address pointed by pbBlob and have a look at the contents. Watch window will not show you full contents.
and dont compare it with the contents of notepad. Open the file in VC++ IDE it will show you all hex as well as text data then compare it.
Regards,
Sandip.
|
|
|
|
|
Enable dispaly unicode strings settings in the IDE.
|
|
|
|
|
Is this option avaialbe in VC++6.0.
Thanks a lot.
Regards,
Sandip.
|
|
|
|
|
|
The following code snippet worked out for me in getting the junk value (stored in the file) into a CString
value.
CString csEncryptedString(_T(""));
char *pEncryptedString = new char;
for (INT i = 0; i < (int)cbBlob; i++)
{
if (pbBlob[i] == '\0')
{
pEncryptedString[i] = '-';
}
else
{
pEncryptedString[i] = pbBlob[i];
}
}
pEncryptedString[cbBlob + 1] = '\0';
csEncryptedString = pEncryptedString;
Thanks all for your various suggestions and support.
Any other efficient code is always welcome.
|
|
|
|
|
How to get Windows user's Login and Logout time?
Nigah M Manzoor
|
|
|
|
|
Using COM it's possible, though I haven't used it at all, just did a quick search and found this for you...
IADsUser COM interface provides these methods for you, google for more information...
get_LastLogin
get_LastLogoff
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
|
thanx,
its working
Nigah M Manzoor
|
|
|
|
|