|
I have a C makefile app which consists of 1 exe and 5 DLL's
These DLL's comunicate with each other via one Main Structure
which has data variables and other structures embedded in it
This main structure is exported and the DLL's that use it import
it
I have written a DLL in C++ makes use of this structure
When I include it I prefix the structure with extern "C" {
since it was orignally devolped in C environment and my Code has
Class and Object and I am compiling it under C++
I have added 2 pointers to this structure
both C DLL's and my C++ build cleanly however ("this is the problem")
The offset for the pointers in the C++ DLL is different (shorter)
then in the C code if some how the code compiled with different
lengths in the C and C++ code
I guess I can always just export the pointer itself from the C code
e.g. __declspec(dllexport) void * mainblk.prta
and import it in the C++ code extern "C" __declspec(dllimport) void * mainbl.ptra
Thankx
|
|
|
|
|
Make sure you include a
#pragma pack( [ show ] | [ push | pop ] [, identifier ] , n )
around your data structure so it is 'seen' as the same size in all projects.
One project probably packs at 2 byte boundaries or 4 and the other at 4 or 8, so they are mismatched, even though they both include the same header file.
Once you do this, your problem should go away.
Any headers you supply to a thid party (or consumed by multiple projects) should have pragma pack aruund all the data structures!
|
|
|
|
|
Still looking through the code (went into disassembly mode in Visual studio) and offsets look right thankx that seems to be it
I have to remember that C and C++ are really two different compilers even though they orignate from the same cl.exe
Thankx
|
|
|
|
|
Just went into disassembly mode and I see the offsets are not right
At least I'm getting closer
|
|
|
|
|
|
I have used it once get rid of slack bytes thankx
|
|
|
|
|
Hello everyone,
Here is the quoted section, words from Bjarne and his sample. The reason why I think the sample is wrong, is because, the member function sort accepts empty arguments, so when we call ::sort (v), only the one in global namespace will be matched -- there is no ambiguity to call sort member function of Container from parameter list comparison. I do not know why Bjarne commets "sort (vector<T>&) which calls std::sort() rather than Container::sort()" -- I think it has nothing to do with template -- just a normal function call matching.
Any comments? Do you agree with me and think his sample is wrong?
section 13.8.3 Point of Instantiation Binding
--------------------
unqualified name can not be bound to members of that class
--------------------
template <class T> void sort (vector<T>& v)
{
sort (v.begin(), v.end());
}
class Container {
vector<int> v;
public:
void sort()
{
::sort (v);
}
};
thanks in advance,
George
|
|
|
|
|
may be he discussed already about the existence of the member function "Container::sort(vector<T>& v)" in the class Container in some other context. And ofcourse, may be not the void Container::sort(void) as it becomes infinite recursion.
|
|
|
|
|
Thanks Rajkumar,
I think you mean it is better to describe in the following way?
sort( v );
which in member function sort of Container class calls
std::sort(vector<T>& v)
other than calls,
Container::sort(vector<T>&v);
regards,
George
|
|
|
|
|
George_George wrote: ::sort (v); // sort (vector<t>& ) which calls std::sort() rather than Container::sort()
The original sample in the book does not use :: .
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
You mean the sample code in your version of book is different from my book and which is,
void sort( vector<int>& v ) { sort( v.begin(), v.end() ); }
class Container
{
vector<int> v;
public:
void sort()
{
sort( v );
}
};
If the above code is what you mean, how does the code reflects the statement from Bjarne?
--------------------
unqualified name can not be bound to members of that class
--------------------
regards,
George
|
|
|
|
|
George_George wrote: You mean the sample code in your version of book is different from my book and which is
Yes.
What is your edition?
Mine is the 3rd Special Edition.
[Added]
George_George wrote: If the above code is what you mean, how does the code reflects the statement from Bjarne?
If it were ::sort(v) instead of sort(v) , then we would have known well that it refers to the global namespace one. There won't be any ambiguity to test whether sort(vector<int>& ) or Container::sort() .
Quote:
sort(v);
Maxwell Chen
modified on Monday, March 10, 2008 7:21 AM
|
|
|
|
|
Thanks Maxwell,
Do you mean your version of book is using the below code? If yes, I do not agree with you that sort(v) will invoke the global sort function sort(vector<t>&), and the code can not compile.
Here is the error message. Any comments?
>d:\visual studio 2008\projects\test_template3\test_template3\main.cpp(15) : error C2660: 'Container::sort' : function does not take 1 arguments
#include <vector>
using namespace std;
template <class T> void sort (vector<T>& v)
{
sort (v.begin(), v.end());
}
class Container {
vector<int> v;
public:
void sort()
{
sort (v);
}
};
regards,
George
|
|
|
|
|
George_George wrote: Do you mean your version of book is using the below code? If yes,
Could you please do not ask that many times of yes/no?! I have already asnwered "yes" in my previous reply.
George_George wrote: error C2660: 'Container::sort' : function does not take 1 arguments
Visual C++ has problem with ISO/IEC 14882 standard. That's all.
You can try other compilers.
Maxwell Chen
|
|
|
|
|
Hi Maxwell,
Thanks and I have got a 3rd edition book to have a common page with you to discuss.
You can compile the following code? I am confused, the following code violates C++ rule, you can see when we invoke sort (v) inside sort member function of class Container, there is no matched function. So, it can not compile. Any comments?
#include <vector>
using namespace std;
template <class T> void sort (vector <T >& v )
{
sort (v.begin(), v.end());
}
class Container {
vector <int> v;
public :
void sort()
{
sort(v);
}
};
regards,
George
|
|
|
|
|
George_George wrote: Any comments? Do you agree with me and think his sample is wrong?
So then why don't you take that up with Dr. Stroustrup rather than bothering us with your disagreements?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks DavidCrow,
How do you understand Bjarne's comments and related sample as I quoted in the original question? If you understand, it is appreciated if you could share your points here.
regards,
George
|
|
|
|
|
Hello everyone,
I am confused about what Bjarne means below, and I quoted the section name, his words and his sample.
My question is, what did he mean "A call that by coincidence has an argument that matches an actual template parameter type is not dependent"?
I think the compile error is because, g (1) function call is not dependent on template parameter, and it should be resolved in the definition phase (not instantiation phase) of template function f. But in definition phase of f, what g is (the symbol g) can not be resolved. So comes the compile error.
Is my analysis correct? What did Bjarne mean?
(section C.13.8.1 Dependent Names)
--------------------
A call that by coincidence has an argument that matches an actual template parameter type is not dependent. For example,
--------------------
template <class T> T f (T a)
{
return g (1);
}
int g (int);
int z = f (2);
thanks in advance,
George
|
|
|
|
|
I've started up Excel and read and posted to spreadsheets using MFC in VC++, but whenever I try to do something new, like draw a chart, it takes me an age to locate the classes and methods I need to do it. Where can I find a good reference on all the classes and methods?
Fred Andres
|
|
|
|
|
Sadly, MSDN doesn't have as much help as it used to, the MSDN that came with VC6 is probably your best bet, if you can get it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
For Excel 2003, see C:\Program Files\Microsoft Office\OFFICE11\1033\VBAXL10.chm or C:\Program Files\Microsoft Visual Studio\MSDN\2001OCT\1033\VBAXL10.chm.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Right, well. I have a struct which so far contains just a char* and a vector of the struct.
Now, i have a function that adds a new item to my vector which takes a char* which is used to initialise my struct:
void AddItem(char* ItemName)
{
myStruct newItem(ItemName);
myVector.push_back(newItem);
}
In the struct constructor i used strcpy to copy the contents of the string rather than the pointer, and i also made a copy constructor which uses strcpy again when copying the struct.
But still, once we leave the function (or should i say, the function in which this function was called) the item, disappears. Debuging it i can see that the item is added and then once we get out of the functions simply vanishes, and i don't understand why.
So, any help of course, would be greatly appreciated.
My current favourite word is: Nipple!
-SK Genius
modified on Sunday, March 9, 2008 8:37 PM
|
|
|
|
|
AddItem() is just a global scoped function? Or is it a method of a class?
What, then, is myVector? What does the myStruct structure declaration look like?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
AddItem is a method of a class.
The whole structure is kind like this:
int main()
{
Class1 myClass;
Class2 myOtherClass;
Class2.DoStuff(myClass);
}
...
Class2::DoStuff(Class1 firstClass)
{
char* text = "SomeText";
firstClass.AddItem(text);
}
It is of course quite different, but its basically the same thing.
The struct looks kinda like this:
struct myStruct
{
public:
char* Name;
myStruct(char* name)
{
Name = new char[100];
strcpy(Name, name);
}
}
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
SK Genius wrote: Class2::DoStuff(Class1 firstClass)
If you are really passing objects by value like that then the scope of
those objects only lasts for the DoStuff() call. After it returns, your original
objects remains untouched.
Maybe you meant to pass it by reference?
Class2::DoStuff(Class1 <font color="Red">&</font>firstClass)
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|