|
Hi all
i use the following piece of code to call an external program, however
i keep getting a warning message returned back which i compile
im using VS2003
the code is
HINSTANCE ok = ShellExecute(NULL, "open", "Update.exe", "NewUpdate", NULL, SW_SHOW);
if ((int)ok > 32)
{
AddToLog("Program run sucessfully",0);
}
else
{
AddToLog("Program failed to run ",0);
}
and the warning message i get back is
(1467): warning C4311: 'type cast' : pointer truncation from 'HINSTANCE' to 'int'
does ne1 have any ideas ??
thanks
si
|
|
|
|
|
si_69 wrote:
if ((int)ok > 32)
nothing to worry about HINSTANCE is 32 bit data while
int is 16 bit data so when you type cast from higher bit size data to lowerbitsize data you tend to loose some data (16 high bits of information)
Logic is perfectly fine in this case and will work without any problem.
If you are still worried about the warning then
put long instead of int.
like this
if ((long)ok > 32)
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Int is 32 bits in all versions of WIN32 Visual C++.
John
|
|
|
|
|
Yeah you are right, he got a warning for trancation of data type, so obviously there was some size difference between the two.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
According to the MSDN documentation, the HINSTANCE return value is not a true HINSTANCE type, but used for compatibility reasons.
So I assume it is safe to ignore the cast warning to an int (or you may suppress the warning with a #pragma, if it bothers you).
msdn ref[^]
I Dream of Absolute Zero
|
|
|
|
|
si_69 wrote:
if ((int)ok > 32)
It's not good practice to use hard-wired numbers in your code. I suggest using HINSTANCE_ERROR instead. Then you can do something like:
HINSTANCE hResult = ShellExecute(...);
if (hResult < (HINSTANCE) HINSTANCE_ERROR)
AddToLog("Program failed to run", 0);
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I'm trying to access function in a class which is defined in another class. I've tried to declare it as a friend, however this won't work for me.
Suggestions much appreciated
Kind Regards
Caoimh
|
|
|
|
|
First either make the methods in the other class as public, or declare ClassB(from the class you are trying to access) as friend in ClassA(whose methods you are trying to access)
other way friendship does not work, its not mutual.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Could you post some example code? Too vague a question to really know what's going on.
Remember, even if you win the rat race, you're still a rat.
|
|
|
|
|
How do I monitor traffic on an already open TCP/IP port? Do I need to use hooks?
|
|
|
|
|
Do either of these tools help:
http://www.sysinternals.com/ntw2k/source/tcpview.shtml
http://www.sysinternals.com/ntw2k/freeware/tdimon.shtml
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
what steps i will have to do before i could use MFC in a win32 non mfc project.
Unmanaged in a .NET world
|
|
|
|
|
Why?????
Isn't much simpler to use Win32 source files in MFC project?
Robert-Antonio
"A flower walked around a meadow. She saw a beatiful human and plucked off his head."
|
|
|
|
|
Well i know it can be that way aswell , but i am more intrested in this cauz i have quite a few win32 projects (not written by me) and i want to extend them with MFC .
So still my question is same
Unmanaged in a .NET world
|
|
|
|
|
Don't you just include the appropriate MFC header files (see StdAfx.h of standard MFC project)?
|
|
|
|
|
If I Include all MFC Headers file it gives in linking error
"void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) already defined in LIBCMT.lib(new.obj)
when compiming in MFC Statis Library mode
Unmanaged in a .NET world
|
|
|
|
|
Sorry, don't know then. Was wondering how to include MFC into Win32 myself. I think it may be best to create an MFC project, and then put or link all your Win32 stuff in there. Only option I can think of.
|
|
|
|
|
Belive me its a pain to convert win32 application to MFC application its not as easy as including few header files and thats it.
Besides ur current win32 logic may stop functioning or give unexected error coz both are off different architecture. and besides there nothing much that MFC can do that win32 can't.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
Well I have solved this issue
1.First of include all headers files present in a MFC project stdafx.h
2.Go to Project --Settings ---General and select either MFC in shared library or MFC in static Library Option
3.In static library option it will give the already defined linking error to solve this issue follow this link and do the apropriate steps as given in this link
http://www.as-ltd.co.uk/cgi-bin/support/faq/XLPFAQ004.htm
after it include stdafx.h where u want to use MFC.
Unmanaged in a .NET world
|
|
|
|
|
Too good man too good.
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
#include <windows.h> or #include <afxwin.h>
After that, the MFC classes should be available to your application.
|
|
|
|
|
Sorry... that is #include <windows.h> or #include <afxwin.h>
|
|
|
|
|
So.. i have made a program with a tray icon in the system-tray. And my problem is, that when explorer is hung and you restart explorer it dosent reload the tray icon..
Does anyone know how i can make the tray icon to reload??
Thanks in advance
Zagzagzag
|
|
|
|
|
From the MSDN
const UINT WM_TASKBARCREATED =
::RegisterWindowMessage(_T("TaskbarCreated"));
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_REGISTERED_MESSAGE(WM_TASKBARCREATED,
OnTaskBarCreated)
END_MESSAGE_MAP(CMainFrame, CFrameWnd)
LRESULT CMainFrame::OnTaskBarCreated(WPARAM wp, LPARAM lp)
{
VERIFY(InstallIcons());
return 0;
}
BOOL CMainFrame::InstallIcons()
{
NOTIFYICONDATA nid;
return Shell_NotifyIcon(NIM_ADD, &nid);
}
Hope you get the idea
MSN Messenger.
prakashnadar@msn.com
|
|
|
|
|
ok.. erhm.. i will try to work it out..
and thank you for your help
just one thing though.. is it supposed to be placed in the Headerfile or the main program's cpp file??
|
|
|
|