|
im develping a Win32 Program with the name """"Add"""" that takes a """string""" as input at command line. The command line argument should be of the following format (commandline argument may be provided from DOS console):
D:\Add\Debug>Add 2,4
The program will extract the integer values from commandline string (e.g. it will extract the values “2” and “4” in above argument) and will add them, finally the result will be displayed in a message box:
wht i did so far
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, LPSTR lpCmdLine, int nShowCmd)
{
LPWSTR *szArgList;
int argCount;
szArgList = CommandLineToArgvW(GetCommandLine(), &argCount);
if (szArgList == NULL)
{
MessageBox(NULL, L"Unable to parse command line", L"Error", MB_OK);
return 10;
}
for(int i = 0; i++; i < argCount)
{
MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK);
}
LocalFree(szArgList);
return 0;
}
|
|
|
|
|
can anyone help me to complete it ,im stuck
thanks
|
|
|
|
|
Is your application compiled with UNICODE support?
Write your WinMain as _tWinMain .
Also you command line must look like Add 2 4 .
Your for loop is wrong.
It must be -
for (int i = 0; i < argCount; ++i)
{
MessageBox(NULL, szArgList[i], L"Arglist contents", MB_OK);
}
|
|
|
|
|
did you mean the fllowing code i tried? having errors
really not getting through !! kindly help me
what i want to have is
------------------------
a Win32 Program with the name “Add” that takes a string as input at command line. The command line argument should be of the following format (commandline argument may be provided from DOS console):
D:\Add\Debug>Add 2,4
The program will extract the integer values from commandline string (e.g. it will extract the values “2” and “4” in above argument) and will add them, finally the result will be displayed in a message box:
-----------------------
what i did
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
LPWSTR *szArgList;
int argCount;
szArgList = CommandLineToArgvW(GetCommandLine(), Add 2 4 );
if (szArgList == NULL)
{
MessageBox(NULL, L"Unable to parse command line", L"Error", MB_OK);
return 10;
}
for (int i = 0; i < argCount; ++i)
{
MessageBox(NULL, szArgList[i], L"Answer is", MB_OK);
}
LocalFree(szArgList);
return 0;
}
|
|
|
|
|
Get a book and learn the basics.
Assignment questions are not appreciated here.
|
|
|
|
|
Ok, so what exactly is the problem? Hint: "It doesn't work" does not qualify as an answer.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi,
I have successfully implemented serialization of various collection classes even when the data contained CStrings so I'm very familiar with the requirements.
However, I have attempted to serialize a CArray <myclass, myclass&=""> MyCArray from a CPropertyPage class (to save various page defaults) and I noticed that the following serialize overrides are never executed when MyCArray.Serialize(archive) is called and CStrings recovered from the archive are either empty or have a bad pointer. Integers recovered from the archive are correct.
CMyClass : public CObject
{
DECLARE_SERIAL(CMyClass)
public:
void Serialize(CArchive& ar);
....
}
class CMyPage : public CPropertyPage
{
DECLARE_DYNAMIC(CMyPage)
public:
CArray < CMyClass, CMYClass& > MyArray;
.....
}
MyClass::Serialize(CArchive& ar)
{
}
and
template <> void AFXAPI SerializeElements < CMYClass > (.....)
Assuming there no's easy fix, is there another simple method could I use to save a small amount of default data to disk (integers and CStrings). I'm just trying to allow the user to save the various property page settings so they do not have to enter them each time.
Thanks
P.S. What's really strange and really frustrating is that on another property page I have a CArray < CString, CString& > MYStringArray and it serializes correctly! Could CPropertyPages have it's own Serialize function ?
modified on Saturday, November 7, 2009 9:12 PM
|
|
|
|
|
Try changing DECLARE_DYNAMIC(CMyPage) to DECLARE_SERIAL(CMyPage)
|
|
|
|
|
Superman,
DECLARE_SERIAL did not help but I forgot to mention that in the module where I write the archive, I have some test code which immediately reads back the archive. In this case, the CArray is always correct.
It's when the Property page is closed, re-entered and the archive read that the CStrings have bad pointers. The doubles and ints are OK. I also occasionally get some odd errors like "out of memory" or a locked buffer assertion when I exit the property page (but only when the property page has read the archive).
I can seperate the CStrings and ints/doubles into 2 different archives/files since the files are transparent to the users anyhow. As I said, a CArray < CString, CString& > serializes OK.
modified on Sunday, November 8, 2009 5:31 PM
|
|
|
|
|
Hello! I acutally program in C# and chose to start learning C++. I have two questions. One would be if I develop a C++ application using visual c++ 2008, is there a way for it to be converted to run on Mac OS X? Or do you have to write it over in a different IDE?
The main question I have is I was trying to learn from this tutorial I found on www.learncpp.com.
It seems the tutorials were geared more towards Visual C++ 2005 and not 2008 (I am using 2008).
I ran into trouble with the headers. The code I am using is from the tutorial so I am confused as to why it is not working?
I noticed a few things different. In the tutorial it doesn't include "stdafx.h" which it needs to compile. Also when trying to use a header file i get these errors:
Error 1 error LNK2019: unresolved external symbol "int __cdecl add(int,int)" (?add@@YAHHH@Z) referenced in function _main HelloWorld.obj HelloWorld
Error 2 fatal error LNK1120: 1 unresolved externals C:\C++\HelloWorld\Debug\HelloWorld.exe HelloWorld
Now I understand it is having trouble reading the add.h file but I am not sure why?
Here is my code:
HelloWorld.cpp:
#include "stdafx.h"
#include <iostream>
#include "add.h"
int main()
{
using namespace std;
cout << "The sum of 3 and 4 is " << add(3, 4) << endl;
return 0;
}
and here is my add.h:
#ifndef ADD_H
#define ADD_H
int add(int x, int y);
#endif
Any help would be great! Thanks!
|
|
|
|
|
Nevermind after looking at it again I figured out why.
I still have to include
int add(int x, int y)
{
return x + y;
}
in the HelloWorld.cpp file right? The tutorial didn't show this. IF thats why then whats the point of putting that other code in the header file when you could add
int add(int x, int y)
at the top of the HelloWorld.cpp file? Or I'm guessing you would put the whole function in the header file instead of what the tutorial just showed
|
|
|
|
|
The whole build process consists of a compilation process and a linking process.
Including the header is for the compiler to figure out the signature of the function.
The linker needs the actual definition of the function.
|
|
|
|
|
Jacob Dixon wrote: One would be if I develop a C++ application using visual c++ 2008, is there a way for it to be converted to run on Mac OS X? Or do you have to write it over in a different IDE?
If you don't use any Microsoft specific functions, you would be able to reuse the code, but you would still need to compile it using a compiler for the MAC.
As for you second question, where is the add function defined?
Is it in another module, like a DLL or a LIB file?
If so you will need to include the LIB file as a dependency in the project settings under -
Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies .
If it is in a .CPP file, you need to include it as part of your project.
|
|
|
|
|
Superman,
That was it, I never defined it. The tutorial just showed
int add(int x, int y) ,
It never showed the rest. So when I put this in the add.h file:
int add(int x, int y)
{
return x + y;
}
It worked perfectly. I should of known better
Thanks for helping out!
|
|
|
|
|
in general, you should avoid putting code in a .H file.
put this in the .C/.CPP:
int add(int x, int y)
{
return x + y;
}
and put this in the .H:
extern int add(int x, int y);
that extern says "there is a function which looks like this, but is implemented somewhere else". that will satisfy the compiler. the linker will take care of the rest.
the reason you don't want to put code in a .H file is that someday you might end up #including that .H into multiple .CPP files, and when you do that, you're going to get linker errors complaining about a multiply-defined symbol called "add".
think of what #include does: the C/C++ preprocessor literally inserts the text of the .H file into the place where you did the #include, before starting the compilation. so if you #include that .H file into multiple .CPPs, you will get multiple copies of the .H file contents. and if the .H file has a function, you'll get multiple copies of that function.
about the only time you'll do implementation in a .H file is if the function is a class member function.
|
|
|
|
|
Ohhh! Ok I understand. I haven't got far into the tutorials just yet but I figure on down they line they will talk about extern and more of the best practices. Thanks guys
|
|
|
|
|
Chris Losinger wrote: about the only time you'll do implementation in a .H file is if the function is a class member function.
Or you're doing a naked inline global function. And about the only time that happens (or should IMNSHO) in C++ programs are those places you need those pesky friend functions that there's just no way around.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Chris Losinger wrote: about the only time you'll do implementation in a .H file is if the function is a class member function.
... or it's a template class.
modified on Sunday, November 8, 2009 3:21 PM
|
|
|
|
|
yep. i was counting that as part of the 'class member function' category.
|
|
|
|
|
Ah. Very good.

|
|
|
|
|
Hi
I am developing a band for Windows Explorer and I want to get notified when the current folder changes. Looks like IExplorerBrowser provides the notifications I need, but I can't get that interface in my SetSite function. I can get IShellBrowser:
STDMETHODIMP CExplorerBand::SetSite( IUnknown* pUnkSite )
{
if(pUnkSite)
{
CComQIPtr<IServiceProvider> pProvider=pUnkSite;
CComPtr<IShellBrowser> pShellBrowser;
if (pProvider)
pProvider->QueryService(SID_SShellBrowser,IID_IShellBrowser,(void**)&pShellBrowser);
}
return S_OK;
} But I don't know what to do to get IExplorerBrowser. I tried QueryInterface on pUnkSite and on pShellBrowser. I tried calling QueryService with IID_IExplorerBrowser and different service IDs. Nothing seems to work.
I'm starting to think that IExplorerBrowser is only intended to be used to host an explorer window in your own application because there are many examples how to create a new instance but not how to get an existing instance.
Any ideas?
Thanks
Ivo
|
|
|
|
|
hello
I want to read and place a .bmp or .jpeg from the disk and create a .doc word file in visual C++
controlling its nature [text wrapping, size etc] is crutial.
please suggest an api or coding
|
|
|
|
|
you could use COM automation to do that.
This signature was proudly tested on animals.
|
|
|
|
|
thank you ,
please suggest some MSDN or other site to have reference.
new to writing such codes
|
|
|
|
|