|
Can you repost the classes in question with the "Ignore HTML tags in this message (good for code
snippets)" checkbox checked on your reply?
That will make it easier to see what's going on
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I will attempt to make this bare bones.
ref class CWafer()
{
public:
CWafer(void);
value struct MyStruct
{
int AnIntegerValue;
array<int>^ AnArrayOfIntegers; // How do I define this to be an integer array of 10 ints.
Init()
{
AnArrayOfIntegers = gcnew array<int>(10) // I have tried this and it does not work.
}
};
array<MyStruct, 2>^ TwoDimensionalArray;
MyStruct newStruct;
}
CWafer::CWafer()
{
TwoDimensionalArray = gcnew array<MyStruct, 2>(1000, 1000);
newStruct = MyStruct.Init();
}
This is it! My application uses an x coordinate and a y coordinate, hence a two dimensional array is perfect because for each (x, y) location there are several integer values and integer arrays that need to be accessed. The above code snippet allows me to write "TwoDimensionalArray.AnIntegerValue = 1;" and I would like to be able to do something like write "TwoDimensionalArray.AnArrayOfIntegers[n] = 2;" but the array is undefined. It seems that the managed heap is being gabage collected before I can use it but I don't see anything wrong with the scope.
|
|
|
|
|
I'm not sure what value (pun intended) you're getting out of using a value struct here, since
you're not creating heap objects and they need to be initialized.
Beyond that, compare the following with your code. Most of the changes were regular C++
related...
ref class CWafer
{
public:
CWafer();
value struct MyStruct
{
int AnIntegerValue;
array<Int32>^ AnArrayOfIntegers;
void Init()
{
AnArrayOfIntegers = gcnew array<Int32>(10);
}
};
array<MyStruct, 2>^ TwoDimensionalArray;
MyStruct newStruct;
};
CWafer::CWafer()
{
TwoDimensionalArray = gcnew array<MyStruct, 2>(1000, 1000);
for (int i = 0; i < 1000; ++i)
{
for (int j = 0; j < 1000; ++j)
{
TwoDimensionalArray[i,j].Init();
}
}
newStruct.Init();
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Okay, getting closer. This has to be a scope issue. Just as before, the two dimensional array was initialized, then the one dimensional array was initialized (inside the CWafer constructor). Then several functions are called from within the constructor, one of those accesses these arrays. When the function is called the arrays become undefined. I suppose I might be able to pass them as arguments but there is some confusion on how gcnew works. In C++ MFC I would declare types in the header file and then create them with "new" in the constructor. Then if I called a series of functions from the constructor I could "see" within the functions the type as I had defined it in the constructor. If I use "gcnew" then call a function from the constructor the definition is immeadiately lost. I saw this same behavior with another class where my CWafer class had to instantiate a CLtx class (contains some parameters that my CWafer class uses). In the CWafer constructor I instantiated a "CLtx^ LtxFile = gcnew CLtx^;" because I wanted all kinds of CWafer functions to use LtxFile. Unfortunately I had to instantiate the LtxFile inside of each function as it was called. This basic difference in scope is huge and causing me all kinds of problems (current one included). I understand that the garbage collected heap will release the memory when it is no longer needed but why is it reclaiming memory just because I have called a function from within the CWafer constructor?
Buck
|
|
|
|
|
The same scoping rules apply as with unmanaged C++.
BuckBrown wrote: Then several functions are called from within the constructor, one of those accesses these arrays. When the function is called the arrays become undefined.
How is this function accessing the arrays if it's not a member function? You must be passing
something, because just like unmanaged C++, you need to have an object to access non-static class
members.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Okay, I slept on it and figured out what was happening, and yes, it is my bad big time. What was happening with the scope was that at some point in time (probably in order to correect a compiler error) I edited the constructor to re-declare the arrays. So when I called a function from within the constructor and had my arrays seem to go undefined was really the debugger referencing the arrays declared in the header file, NOT the arrays re-declared in the constructor. Anyway, I have now got the declarations, definitions, and initializations of these arrays working, but I still think the way CLI does multi-dimensional arrays is for the birds.
Thanks for all your help. Glad to see this started a onversation between you all on that format issue.
Buck
|
|
|
|
|
Actually, the more I look at it, the value struct is fine. I'll drop that topic
And you can change those Int32s back to ints
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am using Visual c++ NET 2005
Who can I set focus to a control in the same form ?
|
|
|
|
|
RTFM
|
|
|
|
|
When in a native c++ class, in a /clr project, stepping through is getting out of sync of where it should be.
i.e.
1 if(fileSpec.GetLength()==0)
2 {
3 printf("You must specify a filename!\n");
4 return 1;
5 }
I put a breakpoint on line 1. Then F11 to step into. The if statement returns false and so it should step to 5 or beyond. Instead it stops on 4.
Any ideas why?
|
|
|
|
|
Hello,
Have you tried deleting all .ncb and .suo garbage, and rebuilding all?
|
|
|
|
|
Hi,
When I am trying to automate MS Word (32 bit) from a NT Service (32 bit). The word runs as a 64 bit application (as evident from the task manager).
But if the same code is run as a thread from a Windows application word runs as 32 bit.
How can I automate word to run as 32 bit from the NT sevice??
Thanks,
Indra
|
|
|
|
|
You;re trying to automate Word using C++ and .NET ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: You;re trying to automate Word using C++ and .NET ?
No, using C++ and COM.
Code I am using:
VARIANT root[64] = {0}; // Generic IDispatchs
VARIANT parm[64] = {0}; // Generic Parameters
VARIANT rVal = {0}; // Temporary result holder
int level=0; // Current index into root[]
// Initialize the OLE Library...
OleInitialize(NULL);
// Line 1: Set oWord = CreateObject Word.Application
CLSID clsid;
CLSIDFromProgID(L"Word.Application", &clsid);
HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER, IID_IDispatch, (void **)&rVal.pdispVal);
rVal.vt = VT_DISPATCH;
VARIANT oWord = {0};
VariantCopy(&oWord, &rVal);
VariantClear(&rVal);
// Line 2: oWord . Visible = 1
rVal.vt = VT_I4;
rVal.lVal = 0;
VariantCopy(&root[++level], &oWord);
hr = AutoWrap(DISPATCH_PROPERTYPUT, NULL, root[level].pdispVal, L"Visible", 1, rVal);
VariantClear(&root[level--]);
VariantClear(&rVal);
// Line 3: oWord . Documents . Open C:\\Test.doc
VariantCopy(&root[++level], &oWord);
hr = AutoWrap(DISPATCH_PROPERTYGET|DISPATCH_METHOD, &root[level+1], root[level++].pdispVal, L"Documents", 0);
The purpose of the AutoWrap function in this sample is to wrap the calls for GetIDsOfNames and Invoke to facilitate automation with straight C++.
|
|
|
|
|
indra20 wrote: No, using C++ and COM.
OK, then you're in the wrong forum. Try the Visual C++ forum.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
I have a C++ (Borland 5.02 - I know is old stuff...anyway) I have function where I can print reports. Now what I need to to modify this function to instead of printing to a printer I need to save that as MDI or PDF file, but I want to bypass the Save As dialog box because I have several hundreds of reports to print. How can I do that? Please help!!!
Flavio
|
|
|
|
|
Borland does not support .NET, therefore you're in the wrong forum. Even in hte right forum, I'm not sure how many people can offer Borland specific help.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
For managed C++ what is the difference between:
using
#using
using namespace
?
Thanks in advance
|
|
|
|
|
A quick look with the F1 key yields:
"The #using Directive...Imports metadata into a program compiled with /clr."
"The using directive allows the names in a namespace to be used without the namespace-name as
an explicit qualifier."
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hey All,
I've run into a problem where under Visual Studio 2005 if a crash occurs in my managed code, I simply get the MS .NET Framework dialog box. Of course it tells me to make sure the reg key is set, debugging info is turned on and that my config file sets <system.windows.forms jitdebugging="true">. I seem to be doing everything, yet I can't get the debugger to open.
Any ideas? Am I missing some other step, or does mixed code fail to invoke the debugger?
Thanks!
Ant
|
|
|
|
|
Hi,
I have some doubts in Virtual functions.
What is the use of Virtual Functions?
In which scenario, virtual functions will be useful ?
For what real time problems, virtual function is preferred?
Please clear my doubt.
Thanks,
Arun AC
|
|
|
|
|
It's all about polymorphism!
A Googly search on "C++ virtual functions" yields billions of articles on the subject (ok, maybe
not that many).
For example: Polymorphic and Virtual Functions in C++[^]
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
After designing my report using Dataset(payroll05DataSet) of my project, How can I fill my Dataset and set Datasource so i can see data on my report.
-- modified at 13:29 Friday 20th July, 2007
|
|
|
|
|
mikobi wrote: How can I fill my Dataset and set Datasource
Have you looked at the scores of .NET Database Articles here on CodeProject?
|
|
|
|
|
CAn you give me the link.
|
|
|
|