|
Currently I am writing the error catching and message displaying portions of my code. Now, although I know my supertight code will never fail and therefore is redundant and will never be used, I still wish to test it.
I am hoping there is some way I can skip chunks of code in the debugger and get directly to the error stuff I want, so I don't have to piss around with changing data or code just to do the testing.
From memory this was possible using Microsft C 6 under OS/2, but what about VC++ 6 under Windows 2000?
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
I would like my program to know at all times:
- Is the mouse in the client area?
- If so then where is it?
And I want to do this without polling GetCursorPos.
A windows message like WM_MOUSEHASJUSTLEFT_YOURCLIENTAREA would be nice because then I could just use the last value I got from WM_MOUSEMOVE without worrying that the mouse has left the premises. Any suggestions?
Thanks!
-Alex
|
|
|
|
|
|
OK... I basically understand how the 'get' portion of a HTTP connection works... but now I have another question.
I am writing a program that will automaticalliy go through various CGI pages, entering the necessary input and parsing the output.
I should be able to handle the parsing, but my question lies in how exactly to 'post' the variables from a form to the CGI page.
EX: The first page has a form that posts a text field named 'Account' and a password field named 'Password' to "main.cgi".
I assume you would get a CHttpFile* that is to the main.cgi and do:
http_file->SendRequest
But it is here that I am not sure what to fill in...
What headers would I need to send? And MSDN says that the lpOptional would usually be the information for a POST operation... but what exactly would I put there?
Thanks for any help you can give!
Adam
cabadam@houston.rr.com
|
|
|
|
|
in.open(m_pFileName, ios::in, filebuf::sh_none);
CString strTemp;
while (!in.eof())
{
char ch;
in.get(ch);
strTemp += ch;
}
.. why does strTemp get an extra FFh char at the end?
-ryan
|
|
|
|
|
eof is one past the last character, equal to -1.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
groove, thanks for the speedy response, ..
-ryan
|
|
|
|
|
I'd just like to make sure of something that I'm kind of worried about.
This is not ok:
char *Foo() {
char ret[100] = "hello";
return ret;
}
This is not ok:
char *Foo() {
char ret[100] = "hello";
return ret;
}
This is ok:
const char *Foo() {
return "hello world";
}
main() {
printf(Foo());
}
Is this right?
Thanks!
|
|
|
|
|
return "hello world"; is fine because the string literal "hello world" is stored in the executable image, and stays allocated for the life of your program.
--Mike--
http://home.inreach.com/mdunn/
"Holding the away team at bay with a non-functioning phaser was an act of unmitigated gall. I admire gall."
-- Lt. Cmdr. Worf
|
|
|
|
|
When you say
<br />
char anArray[200]<br />
you are saying "Grab me 200 characters worth of local space and call it "anArray". You could them go on to put "Hello World" into it if you wanted, but only by copying it in character by character, for example with:
<br />
strcpy(anArray, "Hello World!");<br />
However because the space for anArray is local it's discarded as soon as your function exits. A pointer returned to it will point to garbage, because that pointer looses it's validity when the routine exits.
The string constant "Hello World" is a different kind of beasty. The string is stored by the compiler in static storage. It's address remains valid for the life of the program.
When you say, for example,
<br />
const char *p = "Hello World";<br />
You are allocating a pointer. A memory location containing the address of that static string. Not a new block of memory containing the string itself (which is why it's ok to do a simple assignment in such a case rather than a more complex copy).
Does that make things clearer?
|
|
|
|
|
I need the directory in which the executable is in. I can't seem to find a function that just gets the path for the directory.
If the file path is... c:\program files\cool program\program.exe
I need c:\program files\cool program\
I was hoping to do this by a single function call rather than a hideuos solution by getting the whole path and deleting characters from the end until reaching a \
|
|
|
|
|
Why not call GetCurrentDirectory on startup, and store it ?
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Because GetCurrentDirectory doesn't necessarily return the directory the exe is in. (i think)
I used the debugger and that function, and it showed c:\my documents, while the exe was in c:\my documents\C++ work\Application\Debug\
|
|
|
|
|
How odd - this is how we do it, and have done for as long as I have been here, and it's always worked fine. Are you running it apart from VC, or from within VC ?
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I was running it from within VC, which is probably the problem then.
|
|
|
|
|
GetModuleFileName or GetModuleFileNameEx should work, or you can parse argv[0].
Isn't this in the FAQ yet?
|
|
|
|
|
As I previously mentioned I wanted to get the directory the file is in, not the file name and its full path.
|
|
|
|
|
I think its a simple parse. Once you have the full path just strrchr for the last '\\', then the next to last, and what remains, however improbable, should be your directory.
later
oops - I think just one strrchr would do it - just read your msg again...
|
|
|
|
|
Or better yet, use stl strings.
string dirAndName = "c:\\Test\\SubDir\\File.Ext";
string directoryOnly = dirAndName.substr( 0, dirAndName.findLastOf('\\') );
Of course, this does no error checking, so if you think there might be no '\' character at all then you'd need to rework this slightly.
|
|
|
|
|
how about using _splitpath
cheers
kannan
|
|
|
|
|
"GetCurrentDirectory" will return you the directory that the current process is running in (fairly obvious from the name, really!!). If you create a desktop shortcut this is the "Start In" entry (at least, that's what it's called under 2000 - I can't remember if NT/95/etc use the exact same terminology).
"GetModuleFileName" will return you the path of the file that the specified module (such as a DLL) was loaded into memeory from. If you pass NULL as the first parameter you get the path of the current process module. You may need to process the returned value from "GetModuleFileName" to extract exactly what you want (path only, filename only, etc) - it's been a while since I did anything like this, so I'm not sure!
|
|
|
|
|
But if you call to GetCurrentDirectory when the application start you can get the directory. But dependes the application. If the App is runing like NT service the currentdirectory will be System32
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Here's a crap-load of filename code I use a lot. The function you're interested in is at the bottom, and it relies on one or two of the other functions. You didn't specify, but I assume you're using VC++ and MFC.
Here's the header file (FILENAME.H) :
#ifndef __FILENAME_H
#define __FILENAME_H
CString justFileName(LPCSTR);
CString justName(LPCSTR);
CString justExtention(LPCSTR);
CString justPath(LPCSTR);
CString justDrive(LPCSTR);
CString forceExtention(CString fn, CString newext);
CString forceFileName(CString fn, CString newname);
CString forcePath(CString fn, CString newpath);
BOOL FileExists(CString fn);
int DeleteFile(CString fname);
int RenameFile(CString oldname, CString newname);
void AddBackSlash(CString& path);
CString RemoveBackSlash(CString path);
CString GetProgramPath(BOOL bAndExeName=FALSE);
#endif
And here's the CPP file (FILENAME.CPP) :
#include "stdafx.h"
#include "filename.h"
#include <io.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString justFileName(LPCSTR f)
{
char drive[_MAX_DRIVE],
dir[_MAX_DIR],
file[_MAX_FNAME],
ext[_MAX_EXT];
CString st;
_splitpath((char *)f, drive, dir, file, ext);
st = file;
st += ext;
return st;
}
CString justName(LPCSTR f)
{
char drive[_MAX_DRIVE],
dir[_MAX_DIR],
file[_MAX_FNAME],
ext[_MAX_EXT];
CString st;
_splitpath((char *)f, drive, dir, file, ext);
st = file;
return st;
}
CString justPath(LPCSTR f)
{
char drive[_MAX_DRIVE],
dir[_MAX_DIR],
file[_MAX_FNAME],
ext[_MAX_EXT];
CString st;
_splitpath((char *)f, drive, dir, file, ext);
st = drive;
st += dir;
return st;
}
CString justExtention(LPCSTR f)
{
char drive[_MAX_DRIVE],
dir[_MAX_DIR],
file[_MAX_FNAME],
ext[_MAX_EXT];
CString st;
_splitpath((char *)f,drive,dir,file,ext);
st = ext;
return st;
}
CString forceExtention(CString fn, CString newext)
{
CString st = justPath(fn);
st += justName(fn);
st += newext;
return st;
}
CString forceFileName(CString fn, CString newname)
{
CString st = justPath(fn);
st += newname;
st += justExtention(fn);
return st;
}
CString forcePath(CString fn, CString newpath)
{
CString st = newpath;
AddBackSlash(st);
st += justFileName(fn);
return st;
}
BOOL FileExists(CString fn)
{
BOOL exists = FALSE;
if (!fn.IsEmpty())
{
int status = _access(fn,0);
if (status == 0)
exists = TRUE;
}
return exists;
}
int RenameFile(CString oldname, CString newname)
{
int status = 0;
BOOL oldexists = FileExists(oldname);
BOOL newexists = FileExists(newname);
if (oldexists && !newexists)
CFile::Rename(oldname, newname);
else
status = -1;
return status;
}
int DeleteFile(CString fname)
{
int status = 0;
if (FileExists(fname))
CFile::Remove(fname);
else
status = -1;
return status;
}
void AddBackSlash(CString& path)
{
int length = path.GetLength();
if (length > 1)
{
if (path.GetAt(length - 1) != '\\')
{
path += "\\";
}
}
else if (1 == length)
{
CString temp = path;
temp.MakeUpper();
TCHAR ch = temp.GetAt(0);
if (ch >= 'A' && ch <= 'Z')
{
path += ":\\";
}
else if (ch != '\\')
{
path += "\\";
}
}
else
{
path += "\\";
}
}
CString RemoveBackSlash(CString path)
{
if (path.Find('\\') == 0)
return path;
int len = path.GetLength();
path = path.Left(len - 1);
return path;
}
CString GetProgramPath(BOOL bAndExeName)
{
TCHAR szFullPath[MAX_PATH];
::GetModuleFileName(NULL, szFullPath, MAX_PATH);
CString path = szFullPath;
if (!bAndExeName)
{
path = justPath(path);
AddBackSlash(path);
}
return path;
}
|
|
|
|
|
Thanks for all the input. Just to let you all know, GetCurrentDirectory() doesn't cut it, your current working directory seems to have nothing to do with your exe path. Anyway, the easiest way I found is shown below.
CString File;
GetModuleFileName(NULL, File.GetBuffer(MAX_PATH), MAX_PATH);
File.ReleaseBuffer(File.ReverseFind('\\') + 1);
If the exe path was say... "c:\my documents\code\program\app.exe", the File CString is "c:\my documents\code\program\"
RE: John Simmons / outlaw programmer (or anyone else who knows how to...)
How do you get your code to show up like that on a message? (With the yellow background, and formatting in-tact)
THANKS!
John
|
|
|
|
|
Is it possible to simulate a carriage return in VC++? Basically I’m trying to have my application "push the enter key" on a specified event.
Thanks in advance for your help!
Rob
|
|
|
|