MFC有没有一个函数可以接受两个参数作为系统参数(编译器中的program arguments)

pqiankun 2014-11-21 10:37:25
问题是这样的,我的MFC界面要调用一个FORTRAN动态库,而这个动态库所读取的文件需要在程序参数(编译器中的program arguments)中读取。我的解决办法是:通过DOS运行界面,写出两个参数和该exe,然后运行软件可以接受这两个参数。可是这个办法总感觉太笨。所以问题来了,MFC有没有一个函数可以接受这两个参数作为系统参数?这样我就不需要重新打开EXE,便可以成功调用这个FORTRAN动态库。求大神指点。
...全文
305 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-11-21
  • 打赏
  • 举报
回复
CreateProcess The CreateProcess function creates a new process and its primary thread. The new process executes the specified executable file. BOOL CreateProcess( LPCTSTR lpApplicationName, // pointer to name of executable module LPTSTR lpCommandLine, // pointer to command line string LPSECURITY_ATTRIBUTES lpProcessAttributes, // process security attributes LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes BOOL bInheritHandles, // handle inheritance flag DWORD dwCreationFlags, // creation flags LPVOID lpEnvironment, // pointer to new environment block LPCTSTR lpCurrentDirectory, // pointer to current directory name LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION ); ... lpCommandLine Pointer to a null-terminated string that specifies the command line to execute. The system adds a null character to the command line, trimming the string if necessary, to indicate which file was actually used. The lpCommandLine parameter can be NULL. In that case, the function uses the string pointed to by lpApplicationName as the command line. If both lpApplicationName and lpCommandLine are non-NULL, *lpApplicationName specifies the module to execute, and *lpCommandLine specifies the command line. The new process can use GetCommandLine to retrieve the entire command line. C runtime processes can use the argc and argv arguments. If lpApplicationName is NULL, the first white space-delimited token of the command line specifies the module name. If you are using a long filename that contains a space, use quoted strings to indicate where the filename ends and the arguments begin (see the explanation for the lpApplicationName parameter). If the filename does not contain an extension, .EXE is assumed. If the filename ends in a period (.) with no extension, or the filename contains a path, .EXE is not appended. If the filename does not contain a directory path, the system searches for the executable file in the following sequence: The directory from which the application loaded. The current directory for the parent process. Windows 95 and Windows 98: The Windows system directory. Use theGetSystemDirectory function to get the path of this directory. Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32. Windows NT: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM. The Windows directory. Use theGetWindowsDirectory function to get the path of this directory. The directories that are listed in the PATH environment variable. If the process to be created is an MS-DOS - based or 16-bit Windows-based application, lpCommandLine should be a full command line in which the first element is the application name. Because this also works well for Win32-based applications, it is the most robust way to set lpCommandLine. ...
赵4老师 2014-11-21
  • 打赏
  • 举报
回复
SetCurrentDirectory The SetCurrentDirectory function changes the current directory for the current process. BOOL SetCurrentDirectory( LPCTSTR lpPathName // pointer to name of new current directory ); Parameters lpPathName Pointer to a null-terminated string that specifies the path to the new current directory. This parameter may be a relative path or a fully qualified path. In either case, the fully qualified path of the specified directory is calculated and stored as the current directory. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError. Remarks Each process has a single current directory made up of two parts: A disk designator that is either a drive letter followed by a colon, or a server name and share name (\\servername\sharename) A directory on the disk designator QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winbase.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows NT. See Also File I/O Overview, File Functions, GetCurrentDirectory
赵4老师 2014-11-21
  • 打赏
  • 举报
回复
GetCommandLine The GetCommandLine function returns a pointer to the command-line string for the current process. LPTSTR GetCommandLine(VOID) Parameters This function has no parameters. Return Values The return value is a pointer to the command-line string for the current process. Remarks ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that main and WinMain cannot return Unicode strings is that argc, argv, and lpCmdLine use the LPSTR data type for parameters, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings, because it uses the LPTSTR data type. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winbase.h. Import Library: Use kernel32.lib. Unicode: Implemented as Unicode and ANSI versions on Windows and Windows NT. See Also Processes and Threads Overview, Process and Thread Functions, CreateProcess,WinMain
shen_wei 2014-11-21
  • 打赏
  • 举报
回复
参数需要原来的exe读取文件来确定,, 那你的需要创建进程来获取这个exe确定的参数了。。。 参考 :VC++实现CMD命令执行与获得返回信息
pqiankun 2014-11-21
  • 打赏
  • 举报
回复
引用 2 楼 shen_wei 的回复:
ShellExecute 可以只带参数
我的理解是ShellExecute可以用于打开另外一个应用程序,使另外一个应用程序获得该运行参数,那本来的exe怎么获得呢?我的参数需要原来的exe读取文件来确定,要用ShellExecute,是不是要关掉原先的exe呢?
pqiankun 2014-11-21
  • 打赏
  • 举报
回复
引用 1 楼 wxhxj0268 的回复:
指的是 运行参数?MFC程序可以带参数运行的。
是运行参数,不过这个参数,需要在MFC中打开文件选择后才可以确定,请问用什么函数可以接受?求具体函数
shen_wei 2014-11-21
  • 打赏
  • 举报
回复
ShellExecute 可以只带参数
笨笨仔 2014-11-21
  • 打赏
  • 举报
回复
指的是 运行参数?MFC程序可以带参数运行的。
pqiankun 2014-11-21
  • 打赏
  • 举报
回复
引用 5 楼 shen_wei 的回复:
参数需要原来的exe读取文件来确定,, 那你的需要创建进程来获取这个exe确定的参数了。。。 参考 :VC++实现CMD命令执行与获得返回信息
这个我看了,我就是用这个方法实现的。通过原先exe找到参数,然后重新打开新的exe。但这不是我想要的,我想知道,再不毁坏原先的exe的基础上,能不能让该exe获得运行参数,不要创建新的exe。谢谢
代码静态分析工具PC-LINT安装配置 PC-Lint是C/C++软件代码静态分析工具,你可以把它看作是一种更加严格的编译器。它不仅可以检查出一般的语法错误,还可以检查出那些虽然符合语法要求但不易发现的潜在错误。 C语言的灵活性带来了代码效率的提升,但相应带来了代码编写的随意性,另外C编译器不进行强制类型检查,也带来了代码编写的隐患。PCLint识别并报告C语言的编程陷阱和格式缺陷的发生。它进行程序的全局分析,能识别没有被适当检验的数组下标,报告未被初始化的变量,警告使用空指针,冗余的代码,等等。软件除错是软件项目开发成本和延误的主要因素。PClint能够帮你在程序动态测试之前发现编码错误。这样消除错误的成本更低。 使用PC-Lint在代码走读和单元测试之前进行检查,可以提前发现程序隐藏错误,提高代码质量,节省测试时间。并提供编码规则检查,规范软件人员的编码行为。 由于PC-LINT对于一般程序员来说可能比较陌生,有好多人安装了也不知道怎样配置和使用。 下面我就根据自己的安装和配置心得对PC-Lint的安装、配置及使用进行下详细说明.本人主要介绍了将PC-Lint集成到VC++6.0和SourceInsight的方法和步骤。 (一)Windows下C/C++开发工具,VC6使用较为普遍,因此这里先讲下VC6.0环境集成pclint的步骤. 首先, 当然要下载软件,正版软件要200多$呢,买不起!所以只好网上找免费的拉。从http://www.61ic.com/down/othe/pclint.rar处可以下载到一个8.0版本的pclint. 1.将pclint.rar解压至c:\, 这样lint文件就位与c:\pclint(安装目录)下了。 2.将c:\pclint\lnt 下的3个文件lib-w32.lnt,env-vc6.lnt,co-msc60.lnt拷贝至c:\pclint下, 再在安装目录下创建std.lnt和options.lnt两个文件,其std.lnt的内容如下 // contents of std.lnt c:\pclint\co-msc60.lnt c:\pclint\lib-w32.lnt c:\pclint\options.lnt -si4 -sp4 -i"D:\Program Files;D:\Program Files\Microsoft Visual Studio\VC98\Include" //end 其-i后面的路径名为VC的安装路径和VC Include 文件路径,根据自己的修改便可。 options.lnt 内容可为空,为定制内容,以后需要时再添加。 准备工作做完了,下一步就是要将pclint集成到VC6去,先配置lint使之能对单个C或C++文件进行检查。 1.打开VC6,tools--->customize-->tools 新建一个名为pclint的项,在下面填入 command: C:\pclint\lint-nt.exe arguments: -u c:\pclint\std.lnt c:\pclint\env-vc6.lnt "$(FilePath)" Use Output Window 打上勾 close 完成。 这个在你VC窗口tools菜单下应该多了一个pclint选项,可以用它来运行lint程序,对你的c/c++代码进行静态检查了。 现在就可以用个小程序测试一下pclint了 //test1.cpp #include class X { int *p; public: X() { p = new int[20]; } void init() { memset( p, 20, 'a' ); } ~X() { delete p; } }; 编译这个文件,看下你的编译器给你多少警告,再运行下lint, 可以自己对比一下。 我的机器上,VC产生0 errors 0 warnings, 而lint程序产生了如下8条警告信息,有些还是很有用处的提示,这里就不一一分析了. test.cpp(12): error 783: (Info -- Line does not end with new-line) test.cpp(7): error 1732: (Info -- new in constructor for class 'X' which has no assignment operator) test.cpp(7): error 1733: (Info -- new in constructor for class 'X' which has no copy constru

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧