|
Anonymous wrote:
I'd like to be able to close my program and have the other one still running
CreateProcess will Help in this case, When you use CreateProcess to Execute a Executable, one of it's parameter i.e. LPPROCESS_INFORMATION parameter return with PROCESSID .
Using that Parameter you can control that process i.e.
For terminating the Process :- [TerminateProcess() ]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
From MSDN:
WinExec is provided only for compatibility with 16-bit Windows. Applications should use the CreateProcess function.
Or alternatively, use ShellExecute, which is a "simpler" function call than CreateProcess.
The StartPage Randomizer
|
|
|
|
|
This code will open a program, open a url, open a file, really open anything that has an associated File Type in the registry and Windows knows what to do with it...and it doesn't matter whether you close your program or not. I only call it OpenURL because that is what I mostly use the function for
BOOL CGlobals::OpenURL(CString csURL)
{
SHELLEXECUTEINFO UrlInfo;
memset(&UrlInfo, 0, sizeof(SHELLEXECUTEINFO));
UrlInfo.cbSize = sizeof(SHELLEXECUTEINFO);
UrlInfo.lpFile = (LPCTSTR)csURL;
// TRUE = explorer/netscape window opened (doesn't check for url connection)
return ShellExecuteEx(&UrlInfo);
}
|
|
|
|
|
// Here's a start:
// Run an external command, optionally waiting around
// for it to finish.
bool RunProgram(LPCTSTR progName, LPCTSTR args,
bool wait /*=false*/, int show /*=SW_SHOWNORMAL*/,
)
{
CString commandLine, userName;
PROCESS_INFORMATION procInfo;
STARTUPINFO startInfo;
memset(&startInfo, 0, sizeof(startInfo));
startInfo.cb = sizeof(startInfo);
startInfo.wShowWindow = (WORD)show;
startInfo.dwFlags = STARTF_USESHOWWINDOW | STARTF_FORCEONFEEDBACK;
try
{
// remove leading and trailing spaces
// Trim() is left as an excercise for the reader
commandLine = Trim(progName);
// If there's a space and no double quotes,
// surround the command with double quotes
if (commandLine.Find(' ') >= 0 && commandLine.Find('"') < 0)
commandLine = '"' + commandLine + '"';
commandLine += ' ';
commandLine += args;
LPTSTR lpCommandLine = commandLine.GetBuffer(CommandLine.GetLength() + 32);
if (!CreateProcess(NULL, lpCommandLine, NULL, NULL,
FALSE, 0, NULL, NULL, &startInfo, &procInfo))
return false;
if (wait)
WaitForSingleObject(procInfo.hProcess, INFINITE);
CloseHandle(procInfo.hThread);
CloseHandle(procInfo.hProcess);
}
catch(CMemoryException *)
{
return false;
}
return true;
}
|
|
|
|
|
Hi all,
I need to programmatically enumerate all ODBC drivers installed on a machine. I found some samples, and they work well enough, however I can't find an awful lot of "official" Microsoft documentation on the ODBC APIs themselves.
For example, one of the samples I found uses an API called SQLDrivers(). No problem, it's defined in the latest Platform SDK in sqlext.h. Looking this up in the January 2005 edition of the MSDN library, I'm brought to Servers and Enterprise Development|SQL Server|SQL Server 2000|SDK Documentation|Building SQL Server Applications|ODBC and SQL Server|SQL Server ODBC Driver Programmer's Reference|ODBC API Implementation Details|SQLDrivers, which simply states:
"The ODBC Driver Manager returns all ODBC 3.0-defined SQLDrivers attribute specification strings. For more information about attribute string and value definition, see the ODBC 3.0 documentation."
I'm looking for the actual MS documentation that goes over all the parameters, value returned, possible errors, etc. Where the hell is this??
|
|
|
|
|
I don't think I can help a lot, but maybe you should be looking at SQLBrowseConnect
|
|
|
|
|
> I don't think I can help a lot, but maybe you should be looking at SQLBrowseConnect
I think you misunderstood my question...I don't have any problem enumerating ODBC drivers, per se, but rather I was trying to look for parameter/return value documentation for those SQL*() set of APIs. The section of the MSDN documentation I was looking at essentially describes what the functions do, but do not go into any amount of detail as to what the parameters are, the values returned, error conditions, etc.
For the record, I did find what I was looking for by doing an actual search
It's all under (again, MSDN Library Jan 2005) Win32 and COM Development|Data Access and Storage|Microosft ODBC|Microsoft ODBC|ODBC Programmer's Reference|Part 4 - API Reference|ODBC API Reference.
The funny thing is that with the documentation tree structure opened on both locations, I can see all the same functions being listed twice. Why MS can't organize this better is beyond me...
|
|
|
|
|
Hi,
I'm trying to create a Tooltip control to display tooltip without specifying the hwnd property. Is this possible?
I tried to add a tool to the Tooltip control by specifying the .hwnd property in the TOOLINFO structure as NULL but it doesn't work.
Is it possible in general to display tooltip for application that does not have a Handle?
I read the following post but I don't really understand it as it is in VB:
http://www.codecomments.com/Visual_Basic_Controls/message486687.html
Thanks much - Josh
|
|
|
|
|
Where will your tooltip appear, if you're running a program that doesn't have a window ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
All I want to do is to terminate an application from another application, I can do this by sending wm_close message using postmessage API.
A parameter which postmessage needs is handle to target window this can be found by findwindow, which requires two parameters, window class name or titlebar text. I can't specify title because the title bar text in the target application is not constant. so the only option is window class name.
How can I get window class name of another application, (sdi/mdi), OR
Since the target application is also developed by me how can I set windclss name in that application so that I use same in the terminator applcation.
|
|
|
|
|
Using Spy++? Did you try that utility? It comes free with Visual Studio.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
If you know the location of the other program (XProgram's full path) it's much simpler then that. If you don't know the location..and technically this is the best method rather then hardcoding it in, have the other program write a "ThisIsXProgramsFilePath" registry entry in the InitInstance function (or somewhere that gets hit when XProgram is starting) that the controlling program can read (use a common registry folder...generally your business name). Then use this code from the program that wants control of XProgram:
CString csProgramsFilePath = ...get this from the registry as mentioned above
CWinProcessList process;
DWORD dwProcessID = 0;
DWORD dwProgramID = 0;
if(process.GetProcessInfo(csProgramsFilePath, dwProcessID, dwProgramID))
{
HANDLE hProg = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwProcessID);
if(hProg)
{
if(AfxMessageBox("I'm going to close this program...you OK with that?", MB_YESNO) == IDYES)
{
if(TerminateProcess(hProg, 0))
{
// The program is terminated
}
}
}
else // We failed to get a handle to the program
}
else // The program is most likely not running...or somehow we failed
|
|
|
|
|
pc_dev wrote:
Since the target application is also developed by me
If target application is developeved by you, then it's very easy to find that window, JUST have a look at [RegisterWindowMessage ] api. you will get answer to your question!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi,
i need a program which works with out an installer and can change a file's accessed time. Please help soon.
MFG
RedDragon
|
|
|
|
|
Take a look at SetFileTime function. It will change the time that a file was accessed.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
I am trying to use a CStatic control to allow custom drawing.
Here is the setup. There is a sound library called Bass that has add-ons that allow things such as in my case using Sonique visuals.
To use it you have to amongst other things call the following:
BOOL BASSVISDEF(BASS_SONIQUEVIS_Render)(HVIS handle, DWORD channel, HDC canvas);
I may be going at this all wrong but I am trying to pass this function an HDC to a CStatic control.
CStatic VisWindow; // control variable
<br />
HDC hdc = HDC(VisWindow.GetDC());<br />
BASS_SONIQUEVIS_Render( vischan, chan, hdc);<br />
VisWindow.ReleaseDC((CDC*)hdc);
This is the only way I can get it to compile. Any sugguestions?
|
|
|
|
|
smesser wrote:
This is the only way I can get it to compile. Any sugguestions?
Any suggestions for what? Did you get it to compile or not?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Yes, it compiles but there is another problem.
The C++ interface to the dll I am trying to use is broken at the moment so I can only compile and not link and run.
It just seems I jumped too many hoops for this to work correctly.
The delphi implementation ( provided by author of dll) is really simple.
BASS_SONIQUE_Render( vischan, chan, PaintBox1.Canvas.Handle );
I was thinking that my approach was overly difficult.
|
|
|
|
|
smesser wrote:
...I can only compile and not link and run.
So what's the linker error?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
seem the .lib file that the dll author is not C++ compliant.
First the header file for the dll contains these functions:
void BASSVISDEF(BASS_SONIQUEVIS_CreateFakeSoniqueWnd);
void BASSVISDEF(BASS_SONIQUEVIS_DestroyFakeSoniqueWnd);
They Yield the following error and warnings:
c:\BassVisMFC\BassVisMFC\BassVis.h(49): warning C4229: anachronism used : modifiers on data are ignored
c:\BassVisMFC\BassVisMFC\BassVis.h(49): error C2182: 'BASS_SONIQUEVIS_CreateFakeSoniqueWnd' : illegal use of type 'void'
c:\BassVisMFC\BassVisMFC\BassVis.h(50): warning C4229: anachronism used : modifiers on data are ignored
c:\BassVisMFC\BassVisMFC\BassVis.h(50): error C2182: 'BASS_SONIQUEVIS_DestroyFakeSoniqueWnd' : illegal use of type 'void'
If I comment out from the header those offending lines since I don't seem to need them anyways I then get this linking error.
bass_vis.lib : warning LNK4003: invalid library format; library ignored
|
|
|
|
|
smesser wrote:
HDC hdc = HDC(VisWindow.GetDC());
BASS_SONIQUEVIS_Render(vischan, chan, hdc);
VisWindow.ReleaseDC((CDC*)hdc);
That's not going to work. You need to use:
CDC *pDC = VisWindow.GetDC();
BASS_SONIQUEVIS_Render(vischan, chan, pDC->getSafeHdc());
VisWindow.ReleaseDC(pDC); HDC and CDC* are not the same type - you can't typecast between them.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Finally got a version of the dll from the author and your suggestion works perfectly.
Thanks
|
|
|
|
|
Hi guys
I apologize for reposting this question but probably I didn't reach enough people last night and only got one response that didn't help me much (sorry Chris but thank you).
I'm still strugling with the problem of reading a huge file in the most efficient way. I was suggested last week to "read the file into memory as one big chunk". I think that the advice refered to reading the data in binary format instead of text. Cool... so first I have to translate my text files into binary and then read them... Problem is that all examples that I've found refer to either read a single number or things such as a struct with phone directory...
How about reading a 2 dimensional array of doubles as text, save it as binary and then load it into another array after reading the binary file???
examples???
Thanks a million.
|
|
|
|
|
A file is neither binary nor text as it resides on disk. It all depends on how the file is processed that determines whether it is binary or text. You can open the file and read all of it into memory with something like:
HANDLE hFile = CreateFile("myfile", GENERIC_READ, ...);
LPBYTE lpBuffer = new BYTE[10240];
DWORD dwRead;
ReadFile(hFile, lpBuffer, sizeof(BYTE) * 10240, &dwRead, NULL);
CloseHandle(hFile); Now you can do whatever you want with lpBuffer . You might also benefit from a memory-mapped file.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hi
Sorry if this sounds stupid, please bear with me since I'm a self instructed amateur.
If files are neither text or binary, what's the point of using something like:
To write a binary file
int MyNumber = 10;<br />
ofstream FileOut(FileName,ios::binary);<br />
FileOut.write((char*) &MyNumber, sizeof MyNumber);<br />
fout.close();
and to read
ifstream FileIn(FileName, ios::binary)<br />
FileIn.read((char*) &MyNumber,sizeof MyNumber);<br />
FileIn.close();<br />
Thanks a million you for your help
|
|
|
|