|
Fundamental to the header files is the preprocessor. In order to avoid Multi-Inclusion you need a to tell the preprocessor to only include the header under certain conditions.
For example,
file1.h
<br />
#ifndef __FILE_1_H__<br />
#define __FILE_1_H__<br />
...<br />
#endif<br />
Now with that said, you probably need to revisit your header file design because you should not have a situation where File1 is including File2 and visa versa. If there is common definitions or structures, put those in a separate header. Keep the module specific data in the header that applies to the .CPP or .C module. You application might then look like:
file1.h
<br />
#include "File1.h"<br />
#include "CommonData.h"<br />
...<br />
file2.h would be similar.
Good Luck
Mike Luster
CTI/IVR/Telephony SME
|
|
|
|
|
Hi Virtek,
cross including seems kinda up to date problem. I would suggest that you add #pragma once to both of your header files.
#pragma once
"Specifies that the file will be included (opened) only once by the compiler when compiling a source code file."
Furthermore those two threads might be interesting to you as well.
http://www.codeproject.com/script/comments/forums.asp?msg=1401063&forumid=3785#xx1401063xx
http://www.codeproject.com/script/comments/forums.asp?msg=1422933&forumid=3785#xx1422933xx
regards Tobias
|
|
|
|
|
Do you know why C apply .h & .c file concept.
Becoz in .h file you do all declaration & in .c file you define all function.
so what you do for both header file make .c/.cpp file(which you already done.). & include file1.h in file2.cpp & file2.h in file1.cpp.
so it is not endless loop.
Divyang Mithaiwala
System Engineer & Software Developer
|
|
|
|
|
Divyang Mithaiwala wrote: so it is not endless loop.
It is. Unless you add the folowing
#ifndef _FILE1_H_ // At the beginning of .h file
#define _FILE1_H_ // Win32 style for declaring .h file
#endif // at the end of .h file
|
|
|
|
|
Hello all,
I have a strucure as given below.
public ref struct PASSTHRU_MSG
{
unsigned long ulProtocolID;
unsigned long ulRxStatus;
unsigned long ulTxFlags;
unsigned long ulTimeStamp;
unsigned long ulDataSize;
unsigned long ulExtraDataIndex;
array<unsigned char=""> ^ucData;//[4128];
};
PASSTHRU_MSG ^passThruMsg = gcnew PASSTHRU_MSG;
In Unmanaged Code we used to access the passThruMsg object of this type as (unsigned char*).
There we did not encounter any problem.
But now in Managed Code I'm supposed to convert passThruMsg object to array<unsigned char="">^) or (String^).
But I'm unable to convert it to either of the above mentioned forms.
I'm getting Compilation warning, and a runtime crash.
So, now I'm thinking of filling the data contained in the
passThruMsg object to a (String^) or an
(array<unsigned char="">^).
The issue with (String^) is String::Copy() doesn't work if it encounters a null character.
Please give me an advice which one to use.
Thanks in advance.
Regards
Sunil
|
|
|
|
|
Hi Sunil,
you could try one of these structs
public ref struct PASSTHRU_MSG
{
unsigned long ulProtocolID;
unsigned long ulRxStatus;
unsigned long ulTxFlags;
unsigned long ulTimeStamp;
unsigned long ulDataSize;
unsigned long ulExtraDataIndex;
static array <unsigned char>^ ucData = gcnew array <unsigned char>(4128);
};
or
public ref struct PASSTHRU_MSG
{
PASSTHRU_MSG()
{
ucData = gcnew array <unsigned char>(DATA_SIZE);
}
unsigned long ulProtocolID;
unsigned long ulRxStatus;
unsigned long ulTxFlags;
unsigned long ulTimeStamp;
unsigned long ulDataSize;
unsigned long ulExtraDataIndex;
array <unsigned char>^ ucData;
private:
literal int DATA_SIZE = 4128;
};
regards Tobias
|
|
|
|
|
Hey, I'm new to C++ and I'm having a problem with two classes. I have one class Tray that uses IconWindow, however TrayIcon also uses Tray. Below is the import statements for Tray.h
#pragma once
#include <windows.h>
#include <shellapi.h>
#include "TrayIcon.h"
and the import statements for TrayIcon.h
#pragma once
#include <windows.h>
#include <commctrl.h>
#include "Tray.h"
However, this does not compile as they both rely on the other to be compiled first.
I'd apreciate any thoughts on if I am correct and how it could be fixed.
Many Thanks
theonewithtom
|
|
|
|
|
Hi
If I understood you right then this could be a solution for your problem:
http://www.codeproject.com/script/comments/forums.asp?msg=1401063&forumid=3785#xx1401063xx
regards Tobias
|
|
|
|
|
Thankyou for your response. At first the code appeared to compile, however, I seem to be unable to call any functions of my second class. My code is now:
ClassA.h
#include "classB.h"
public __gc class A {
...
}
ClassB.h
public __gc class A;
public __gc class B
{
A a = new A();
...
}
When I compile I get an error saying 'no appropriate default constructor available'.
Any Suggestions?
Many Thanks
theonewithtom
|
|
|
|
|
you shoud use a default constructor.
public __gc class B
{
public:
B()
{
A a = new A();
}
B(Int32 i)
{
A a = new A();
}
~B(){}
}
|
|
|
|
|
Sorry I probably didn't phrase my question propperly. Class A is already declared in ClassA.h with it's header etc, however, I want to use it in ClassB.
I think I'm asking the same question as 'Simple question about header files'
http://www.thecodeproject.com/script/comments/forums.asp?forumid=3785&select=1423769#xx1424478xx[^]
<br />
ClassA.h<br />
<br />
#include "classB.h"<br />
<br />
public __gc class A {<br />
...<br />
}<br />
<br />
ClassB.h<br />
<br />
public __gc class A;<br />
<br />
public __gc class B<br />
{<br />
A a = new A();<br />
...<br />
}<br />
Many Thanks
theonewithtom
-- modified at 6:29 Tuesday 28th March, 2006
|
|
|
|
|
In class B use
#include "classA.h"
in class A use
#ifndef _CLASS_A_H_ // Win32 definition style instead #progma once
#define _CLASS_A_H_ // use this definition style if you want to include
public __gc class A {
...
};
#endif
ps: Don't forget to add ";" at the end of class
|
|
|
|
|
I'm not sure if you already figured this out, but you can use a forward declaration of a class like you can with functions/methods. Ex.
class myclass2; //forward declaration of a class.
class myclass1
{
myclass2 m_SecondClass;
....
};
class myclass2
{
myclass1 m_FirstClass
};
DWyvern
|
|
|
|
|
Whitch .NET framework are you using. If you use plain C++, then this thread supposted to be in Visual C++/MFC Forum.
I don't use Forward decleration. I sometimes declare a global class.
|
|
|
|
|
I have a c# app which references a managed c++ class dll which is wrapping an unmanaged win32 dll using the method described here[^]. I have set the c# app's properties to allow unmanaged code debugging (VS2005), but I am still unable to step into the win32 dll code. Everything is in the one visual studio solution. I have created a pre-build event for the c# app to copy the win32 dll to the c# apps debug folder (Id rather not have to do this, but it seems necessary).
Can someone please help me figure out why i cant debug the dll?
|
|
|
|
|
modify the project settings of the managed c++ project, change the output and debug target according to the C# app. start debugging from the managed c++ project.
My blogs:
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
http://bloglines.com/public/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
Sorry, but I can't see any settings like that... what exactly are they called? Im using Visual Studio 2005.
|
|
|
|
|
Never mind, figured out my problem thanks. In the properties for the win32 project I had Linker>Debugging>Generate Debug Info turned off
|
|
|
|
|
Sir,
I want to connect vc++.net1.1 with sql server 2000.
In this I want to dynamically establish the connection and want to add the buttons named add , delete , edit , update , first, previous , last , next. In all these buttons I want to use the sql queries.
Can you please send me the code project links
I shall be very thankful to you.
Pankaj Garg
|
|
|
|
|
Sir,
I want to learn the deployment in vc++.net1.1.
Can you send me the tutorials.Or any link Please.
THANK YOU
Pankaj Garg
|
|
|
|
|
I have a problem when calling a function existing in the principle dialog from another dialog in the same project.this call creates an assertion failure exception when executing the following instruction:UpdateData(true) which is necessary to send a message via a socket in the principle dialog.
please help me.
lilas23
|
|
|
|
|
Hi
The problem is concerned with expanding and collapsing the treview node.
Like I expanded c: and c: shows windows , document and settings , program files.etc.Like
c:
My Documents
Windows
Program Files
Then next time I Unexpand the C: node.
Finally Again I Expand the C: node.
It shows the following structure.
C:
My Documents
Windows
Program Files
My Document
Windows
Program Files
I mean It show duplicacy of the three nodes two times .
If i delete the sub node on openeng the C:
Please tell me the way.
I am using action == 2 function.
even then it is showing the same problem
Thanks
|
|
|
|
|
hi,all
i am a new comer to this group
While programming i got an error which is some reference error or some thing else
Anyways i will give u my doe pls help me
#include <conio.h>
#include <string.h>
#include <iostream.h>
char* rmstr(char *whstr, char *strm)
{
char *ptr,*rem;
char temp[20];
clrscr();
int k=0;
do
{
ptr=strstr(whstr,strm);
if (ptr==NULL)
{
break;
}
for (int i=0;i
|
|
|
|
|
Would you mind posting it again? But this time please check "Ignore HTML tags in this message (good for code snippets)" because the code you've posted is currently incomplete.
for instance:
>> for (int i=0;i{
>> temp[k++]=whstr[i];
>> }
btw. The line below is probably causing your trouble.
strcpy(rem,whstr);
The rem pointer has not been initialized before or to be more precise you haven't allocated any memory, even though you're applying strcpy on it.
cheers Tobias
|
|
|
|
|
oh........
thanks for this valuable help
its get ok when i initialised it as u suggest
thanks thanks thanks a lot
shamnar
|
|
|
|