|
You could use the "CreateProcess" API. Here is what a typical call would look like:
-----------------------------------------------------------------------------------
STARTUPINFO si = {0};
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
BOOL bOk = CreateProcess(
"C:\\Windows\\System32\\Notepad.exe", // LPCTSTR lpApplicationName
NULL, // LPTSTR lpCommandLine,
NULL, // LPSECURITY_ATTRIBUTES lpProcessAttributes,
NULL, // LPSECURITY_ATTRIBUTES lpThreadAttributes,
FALSE, // BOOL bInheritHandles
0, // DWORD dwCreationFlags
NULL, // LPVOID lpEnvironment
NULL, // LPCTSTR lpCurrentDirectory
&si, // LPSTARTUPINFO lpStartupInfo
&pi // LPPROCESS_INFORMATION lpProcessInformation
);
if ( bOk )
{
pi.CloseHandle(pi.hProcess);
pi.CloseHandle(pi.hThread);
}
There are other options like "ShellExecute" and "ShellExecuteEx" and CRT functions such as "_spawn".
Steve
|
|
|
|
|
I want to be able to cause Microsoft Word to load(run) with a particular ".doc" displayed and when the user finishes the document and selects the [-] min or [X] close button in Mircosoft word the user returns to exactly where he/she left off in the program.
How can this be done AUTOMATICALLY from within a program? EXAMPLE of working code PLEASE!
C++ is my favorite programming language
|
|
|
|
|
You can call a ShellExecute on the filename of the doc you want to open.
SHELLEXECUTEINFO sei;
ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof (SHELLEXECUTEINFO);
sei.lpVerb = "open";
sei.lpFile = curPath;
sei.nShow = SW_SHOW;
sei.hInstApp = NULL;
sei.lpDirectory = strPath;
sei.fMask = SEE_MASK_DOENVSUBST|SEE_MASK_NOCLOSEPROCESS;
sei.lpParameters = NULL;
ShellExecuteEx (&sei);
Where curPath is the filename (including path) and strPath is the name of the working directory.
This will call the default program for the specified filetype to open with that file. If the user has a different program defaulted for opening up .doc files (like wordperfect or something), then this will not open word.
Kelly Ryan
|
|
|
|
|
Hi ,
I guess you need to use automation ,by this way you export all the function provided by the word type library, you can do all the sort of work in that word like if the user is doing it, you can set the setuservisible(true),("i guess so ") ,and that word becomes visible to the user ,
i havent tried this on word, but on excel and it works wonderfully.
Regards
FarPointer.
|
|
|
|
|
I would like to know how to send a shortcut to the desktop from within a program?
Can anybody give me a working example?
C++ is my favorite programming language
|
|
|
|
|
|
Hi,
I have a VC++(mfc) classes written especially as base class for enhancing menu's in MFC modules.
Now i want to make use of this classes(vc++)for enhancing menu's in a vb6.0 module aswell. So these classes will be accessed by mfc & vb at same time.
1. How do i do this, do i create a dll?, if so what dll?, there are diff options in MFC wizard, which one do i choose to create?
2. Do i need to make any modifications in existing classes to export to VB
Please anyone give me an Idea.
Thanking you
Mo
|
|
|
|
|
what does your MFC class do?
just some menu functions (i.e. delete menu item) or a visible menu interface?
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
|
|
|
|
|
It loads different menu's from resource(.rc) according to the doctemplate & adds icon to it,plus adds some other enhancments.
Mo
-- modified at 6:55 Saturday 14th January, 2006
|
|
|
|
|
I am extremely fed up with the resource editor in VS2005. Not only does it regularly crash VS2005 (usually when adding a new dialog), I am now having problems adding a variable from the dialog editor to an associated class.
My Setup in my solution:
- I have a resource only dll that contains only the resources and not the code behind it. In other words it basically only has Resource.rc file and Resource.h file.
- Another project (a library) contains the source code associated with the dialogs and property pages in the Resource.rc file.
- The way I associated the Resources with the code was by adding the Resource.rc file into the other project (the library) and then excluding it from the build.
This seemed to work at first. When I go to add an event handler for say a button, the handler gets added just fine into the correct .cpp and .h file that corresponds to the dialog that contains the button.
The issue I am having is, when I right click on the same button and select "Add Variable", the "Control Id" field is blank and disabled. The Control Id of the button is supposed to be filled in. Why is this happening? If it can add a handler properly, why can't it add a variable?
Also, is there a better way of associating the resources with the code when the resources are contained in a resource only dll and the code in a separate project?
Please Help. This has been frustrating me ever since we upgraded VS 6.0 to VS 2005.
Thanks in advance.
|
|
|
|
|
Hello all,
I am writing an assert function and don't know how to do certain things,
1. How can I know the file name of the code that cause the assert?
2. How can I know the line number of the code that cause the assert?
3. How can I know the function name of the code that cause the assert?
4. How can I print out the call stack when I get the assert?
5. Can I get the PC and SP register information when I get the asset?
Thanks!
Nacho
|
|
|
|
|
1. How can I know the file name of the code that cause the assert?
A: The "__FILE__" macro.
2. How can I know the line number of the code that cause the assert?
A: The "__LINE__" macro.
3. How can I know the function name of the code that cause the assert?
A: Possible but hard - See 4.
4. How can I print out the call stack when I get the assert?
A: There are article on the codeproject and else where on this - It is a bit involved.
5. Can I get the PC and SP register information when I get the asset?
A: Inline assembler:
#pragma optimize("y", on) // Force use of frame pointers
DWORD GetMyReturnAddress()
{
DWORD ReturnAddress;
__asm
{
mov eax, [ebp+4]
mov dword ptr[ReturnAddress], eax
}
return ReturnAddress;
}
#pragma optimize("", on) // Resets the optimizations
DWORD _ESP;
__asm
{
mov dword ptr[_ESP], ESP
}
DWORD _EIP = GetMyReturnAddress();
Steve
|
|
|
|
|
1: The __FILE__ macro.
2: The __LINE__ macro.
3: The __FUNCTION__ macro.
4: This requires that you be able to manipulate the symbolic debugging information for the program in question. Essentially, you have to be able to do the same things as a debugger. This is not trivial, and requires detailed specifications of the debugging symbols, which isn't always available.
5. Yes. Generally, in C, on entry to any given function the top-most item on the stack is the return address. Just above the return address are any function arguments. Since you are now inside your assert function, and you (I would assume) know the arguments, you can 'back up' the stack pointer to reach the stack contents at which your assert function was called.
The question remains, why are you implementing your own assert function?
assert is provided for you.
Software Zen: delete this;
|
|
|
|
|
Gary R. Wheeler wrote: The question remains, why are you implementing your own assert function?
assert is provided for you.
I don't know Nacho's reason, but I have the need to be able to comprehensively report an error (file, line, function, and stack trace) and then continue the program with error recovery.
The idea is that a customer could snap the info and report it back and then I would have a fighting chance of figuring out the problem. And if automatic error recovery worked, then the customer is not facing a complete crash like assert() gives.
Further, not all code runs under Windows. An heretical thought, but there it is!
|
|
|
|
|
Harold Bamford wrote: not all code runs under Windows
assert is a Standard C/C++ library feature, and it not Windows-specific.
Software Zen: delete this;
|
|
|
|
|
But it does cause an abort. Not always a nice thing for an embedded system. Thus the need to write an alternative.
|
|
|
|
|
Hi,
I'm writing a network application and I need to retrieve informations about network computers : MAC address, Host Name, IP, shared resources...
I suppose something suitable exists in Microsoft API but I don't know where.
I've tried Windows Networking but it seems a bit limitated.
Can someone help?
Thanks
|
|
|
|
|
Winsock API in MSDN will be a good place to look for the information you require.
Z.A
|
|
|
|
|
zubair_ahmed wrote: '06
Winsock API in MSDN will be a good place to look for the information you require.
AFAIK and IMHO, Using Winsock api you can only transfer data, you cannot recv any network or lan related data.
"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
|
|
|
|
|
Allad wrote: I'm writing a network application and I need to retrieve informations about network computers : MAC address, Host Name, IP, shared resources...
look for IPhelper apis
"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
|
|
|
|
|
I have a window or dialog box (class derives from CFormView) that needs to be updated when the mouse is clicking on any of the items in the menu bar or when the focus leaves the dialog box. There are two cases:
(1) When there are other child windows open in the app, is there an OnKillFocus that I can call to do the update?
(2) Also, when the window is the only open window in the application, and the user selects a menu item, KillFocus will not work since it's still the active window. How do I know the focus is now on the menu bar?
Thanks!
|
|
|
|
|
Call CWnd::UpdateDialogControls and it will process all OnUpdate messages for your window.
John
|
|
|
|
|
Hi.
<small>How do I know the focus is now on the menu bar?</small>
you can do a WM_NCHITTEST Notification it returns a ,HTMENU if its on a menu ,( the DefWindowProc function returns that ) if its an HTMENU you can do your concerned work ,i guess this might help you.
Regards
FarPointer.
|
|
|
|
|
I have a small problem that I cannot find concerning GetItemDataPtr/SetItemDataPtr for the ComboBox.
I do something like this to insert an item :
void MyCombo::InsertString( MyPointer* pMyPointer )
{
int iIndex = AddString( pMyPointer ->name );
SetItemDataPtr( iIndex, pMyPointer );
}
and this to get the data.
/// p is a struct that also contains a name
MyPointer* MyCombo::InsertString( int iIndex )
{
MyPointer* p = ( MyPointer*) GetItemDataPtr( iIndex );
}
at this point, the pointer in the combobox is invalid ( 0x00000001 )
I'm not certain where to start looking for clue to why this happens.
Thanks for info, tips, insights.
Max.
Edit :
Ok, Found the problem, someone else is doing a SetItemData somewhere else, and overwrites the pointer !!!!
Maximilien Lincourt
Your Head A Splode - Strong Bad
-- modified at 13:33 Friday 13th January, 2006
|
|
|
|
|
I am getting data from a database via CDaoRecordset. The data is coming back in a COleVariant from which I am reading it. However some of the fields in the database are empty which means the COleVariant is also empty. When I try to read an empty COleVariant the program crashes. This occurs when I try to convert the data to a string or date etc.
CString vData;
COleVariant vVarData;
vData = V_BSTRT(&vVarData); //crashes here if the string is empty!!
This works perfectly if the database field and thus the COleVariant is not empty. Does anybody know how to detect an empty COleVariant before trying to actually read it?
Your help would be appreciated
Dave Collins
|
|
|
|