Article View: borland.public.cppbuilder.nativeapi
Article #15710Re: Run program against file
From: Ed Mulroy [TeamB]
Date: Mon, 16 Jun 2003 20:55
Date: Mon, 16 Jun 2003 20:55
115 lines
4469 bytes
4469 bytes
I copied that code to my machine, built it into a program and ran
it. It worked although the title of the file selection dialog was
"somefile.exe", a rather unusual title for such a thing.
If GetDesktopWindow is a problem for you then you could use
NULL for that calling parameter. However it should work as is.
Why do you think GetDesktopWindow is a problem? What
indications do you have of that?
However if that window handle is a problem, then make your
own window and use its handle. Code to do that is below.
When saved as q395d.cpp and built with the following command
line it created a 6,656 byte executable that did the job.
bcc32 -RT- -x- -WR q395d noeh32.lib
Or you could use a simpler command line such as the one below
which static links and does not stub out exception handling and
runtime type id to get a 51,712 byte version that does the same
thing
bcc32 -W q395d
Note that I have kept the changes you made, copying almost
exactly what you posted into the program.
-------------------------
#include <windows.h>
WORD WINAPI SelectFile(
HWND parent,
const char *initial_directory,
const char *
title,
char *full_name)
{
OPENFILENAME ofn;
char file_name[MAX_PATH + 1];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = parent;
ofn.lpstrTitle = title;
ofn.nMaxFileTitle = lstrlen(title);
*full_name = '\0';
ofn.lpstrFile = full_name;
ofn.nMaxFile = MAX_PATH + 1;
ofn.lpstrFileTitle = file_name;
ofn.nMaxFileTitle = MAX_PATH + 1;
ofn.lpstrInitialDir = initial_directory;
ofn.lpstrFilter = "Executable Files\0*.EXE\0\0";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_LONGNAMES |
OFN_NOREADONLYRETURN | OFN_HIDEREADONLY |
OFN_PATHMUSTEXIST | OFN_EXPLORER;
SetLastError(0);
if (!GetOpenFileName(&ofn))
{
DWORD errnum = CommDlgExtendedError();
char err_buf[512];
wsprintf(err_buf, "File Selection Error %08X/%u", errnum);
MessageBox(parent, err_buf, "", MB_OK);
*full_name = '\0';
*file_name = '\0';
ofn.nFileOffset = (WORD) -1;
}
else
{
// create a pointer to the 1st char following the directory
lstrcpy(file_name, full_name + ofn.nFileOffset);
}
return ofn.nFileOffset;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
char file_name[MAX_PATH + 1];
int result = SelectFile(GetDesktopWindow(),
"C:\\",
"sumfile.exe",
file_name);
if (result != -1)
{
MessageBox(HWND_DESKTOP, file_name,
"Selected File", MB_OK);
}
return 0;
}
-------------------------
. Ed
> cpp3003 wrote in message
> news:3eee1a55$1@newsgroups.borland.com...
>
> Yes, I have compiled other programs which do work.
> The coding below is what I am attempting to run. Have
> I misapplied this code in any way ? It compiles
> without error. GetDesktopWindow does not appear to
> be working, for some reason. I have no clue what to do
> for this.
Technical Details
Message-ID:
<3eee2ee4@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ee8f082$1@newsgroups.borland.com> <3ee8fc5c@newsgroups.borland.com> <3ee9dde6$1@newsgroups.borland.com> <3eea79f9$1@newsgroups.borland.com> <3eedd330$1@newsgroups.borland.com> <3eedf7f3@newsgroups.borland.com> <3eee0645$1@newsgroups.borland.com> <3eee1411$1@newsgroups.borland.com> <3eee1a55$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,7bb2502e61022b33 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-06-16 14:04:38 PST From: "Ed Mulroy [TeamB]" <ed@mulroyREMOVETHESECHARS.org> Newsgroups: borland.public.cppbuilder.nativeapi References: <3ee8f082$1@newsgroups.borland.com> <3ee8fc5c@newsgroups.borland.com> <3ee9dde6$1@newsgroups.borland.com> <3eea79f9$1@newsgroups.borland.com> <3eedd330$1@newsgroups.borland.com> <3eedf7f3@newsgroups.borland.com> <3eee0645$1@newsgroups.borland.com> <3eee1411$1@newsgroups.borland.com> <3eee1a55$1@newsgroups.borland.com> Subject: Re: Run program against file Date: Mon, 16 Jun 2003 16:55:49 -0400 Lines: 117 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 24.74.175.102 Message-ID: <3eee2ee4@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1055796964 24.74.175.102 (16 Jun 2003 13:56:04 -0700) X-Authenticated-User: edmulroy Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!sn-xit-08!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail