question about namespaces

hi

about namespaces,

I am defining a class in a separate file.h that I then #include-ing to the main file.

when I define a namespace in the separate file I get a lot of errors.

Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "stdafx.h"
namespace OPEN
{
	class OpenCloseApp
	{
	public:
		void OpenAppl (LPCWSTR pathToOpen);
	};

	void OpenCloseApp::OpenAppl(LPCWSTR pathToOpen)
	{
		PROCESS_INFORMATION pi; 
		DWORD  dw;
		memset(&pi, 0, sizeof(pi)); 

		if(!CreateProcessW(pathToOpen,NULL,NULL,NULL,FALSE, CREATE_NEW_CONSOLE,NULL,NULL,NULL,&pi))
		{
			MessageBox(NULL,TEXT("Error!!"),TEXT("Windows CE message"),MB_OK);
		}
		
	//	printf("dw is equal to: %u n", dw);
		dw = GetLastError(); 
	}
} // end of namespace 


and here are the errors in the main file:

1>.SilverlightSample.cpp(18) : error C2143: syntax error : missing ';' before '*'
1>.SilverlightSample.cpp(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.SilverlightSample.cpp(18) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>.SilverlightSample.cpp(29) : error C2065: 'OpenMyApp' : undeclared identifier
1>.SilverlightSample.cpp(29) : error C2227: left of '->OpenAppl' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>.SilverlightSample.cpp(48) : error C2227: left of '->OpenAppl' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>Build log was saved at "file://c:Documents and SettingsnathanielMy DocumentsVisual Studio 2005ProjectsCopy of SilverlightSampleSilverlightSampleSilverlightSample_SDK (ARMV4I)DebugBuildLog.htm"
1>SilverlightSample - 6 error(s), 0 warning(s)

those errors are related to following class, defined in another file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class BtnEventHandler
{
public:
	OpenCloseApp *OpenMyApp;

public:

	HRESULT OnClick(IXRDependencyObject* source,XRMouseButtonEventArgs* args)
	{
		BSTR pName;
		source->GetName(&pName);

		if (_tcscmp(L"But1", LPCWSTR(pName)) == 0)
		{
			OpenMyApp->OpenAppl(L"\Storage Card\solitare.exe");
	//		ps->szName = L"Solitare";
	//		ps->dwDelay = 1000;
	//		MessageBox(NULL,TEXT("GPS Application"),TEXT("Silverlight for Embedded test"),MB_OK);
		}
		else if (_tcscmp(L"But5", LPCWSTR(pName)) == 0)
		{
			OpenMyApp->OpenAppl(L"\Storage Card\iesample.exe");
		}
		return S_OK;
	}
};


I don't make any use of this namespace for the moment, the only fact of defining the namespace make errors. If I erase the namespace definition, it is then compiling.

Thank you for your help,

Nathaniel


You could use OPEN::OpenCloseApp in the declaration of OpenMyApp.
it is not working so much!!

I am getting the error: 1>.OpenCloseApp.cpp(6) : error C2653: 'OpenCloseApp' : is not a class or namespace name

Any idea?

Thank you,

Nathaniel
Like simeonz wrote. Whenever you want to access 'OpenCloseApp' outside the namespace 'OPEN' you must write OPEN::OpenCloseApp
OpenCloseApp is defined in a header file that you include, right? The class definition must be in a header file and the class member definitions must be in an implementation (.cpp) file.

Regards
Topic archived. No new replies allowed.