|
I have a medium sized (27 projects) solution which has a mixture of project types, libs (both MC++ and C++), DLL's (both MC++ & C++) and exes all MC++.
I am considering upgrading the project to vc 2008 mainly because this is the only project that I look after that needs VC 2003 and would like to use one development environment for everything. (have successfully upgraded all my VC2005 projects to VC2008)
During the upgrade I was considering doing a 'proper' upgrade of all the code e.g. changing __gc class to ref class and using gcnew as required.
Anyone know of any undocumented issues that might make this upgrade a failure or accelerate hair loss!
Robin
|
|
|
|
|
I personally would take the time to upgrade all the Managed Extensions
code to C++/CLI format. The old syntax is still supported (with a
compiler option) but the Managed Extensions are deprecated (and not
as clean to read/use as the C++/CLI format).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am trying to use a cliext::list<> and am hitting various problems - apologies, its a long one - but stick with me . Before I start, I am using Visual Studio 2008 with service pack 1. I am (relatively) new to mixed mode programming - my background is pure C++ / MFC, etc - so it is entirely possible I am misunderstanding something. I have reduced my first problem to the following:
Header file:
#pragma once
#include <cliext/list>
private ref class TestClass
{
cliext::list<int> ^ m_list;
public:
TestClass(void);
};
.cpp file:
#include "StdAfx.h"
#include "TestClass.h"
TestClass::TestClass(void)
: m_list(gcnew cliext::list<int>())
{
}
Produces this little lot... (project name is LNK2022)
1>------ Build started: Project: LNK2022, Configuration: Debug Win32 ------
1>Linking...
1>TestClass.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: cliext.impl.list_impl<int,0>; fields: _Myhead): (0x0400000a).
1>TestClass.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: cliext.impl.list_impl<int,0>; fields: _Mysize): (0x0400000b).
1>TestClass.obj : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types (types: cliext.impl.list_impl<int,0>; fields: _Mygen): (0x0400000c).
1>TestClass.obj : error LNK2022: metadata operation failed (801311D7) : Differing number of fields in duplicated types (cliext.impl.list_impl<int,0>): (0x02000023).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: cliext.impl.list_impl<int,0>; interfaces: System.Runtime.CompilerServices.CallConvStdcall): (0x09000001).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: cliext.impl.list_impl<int,0>; interfaces: System.IDisposable): (0x09000002).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: cliext.impl.list_base<int,0>; interfaces: System.Runtime.CompilerServices.CallConvFastcall): (0x09000003).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118B) : Inconsistent implemented interfaces in duplicated types (types: cliext.impl.list_base<int,0>; interfaces: System.Runtime.CompilerServices.CallConvThiscall): (0x09000004).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (cliext._Dehandle<int>): (0x02000021).
1>TestClass.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (cliext.is_handle<int>): (0x02000022).
1>LINK : fatal error LNK1255: link failed because of metadata errors
1>Build log was saved at "file://i:\dev\ians stuff\LNK2022\LNK2022\Debug\BuildLog.htm"
1>LNK2022 - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Does anyone have any ideas? If I initialise the list in the header, the program compiles and links ok.
Ok, fine, I can live with that unless I want to hide my implementation of the constructor in the .cpp to reduce dependencies (my code is more complicated).
Anyway, next problem...
Header file:
#pragma once
#include <cliext/list>
private ref class TestClass
{
ref struct SInside
{
int mem1;
};
cliext::list<SInside ^> ^ m_list;
public:
TestClass()
: m_list(gcnew cliext::list<SInside ^>())
{}
};
No particular rocket science here, a nested struct being used as the type for the list container. Note initialisation in header - constructor removed from .cpp 'cos of point one above.
As soon as we construct the an object of type TestClass with the following in the form constructor:
TestClass ^ tmp = gcnew TestClass();
I get a message box with the following (my test app compiles to LNK2022.exe):
An unhandled exception of type 'System.TypeLoadException' occurred in LNK2022.exe
Additional information: Access is denied: 'Microsoft.VisualC.StlClr.IList`1[TestClass+SInside]'.
I am really not sure even what this is trying to tell me, but what I do know - after a lot of searching and head scratching (and randomly moving code) - if I move the nested struct outside of the class declaration, everything is fine. Again, in my real example this reduces my encapsulation, and I would rather not do it if possible.
If I move the nested struct to a public section of the class, all is ok too. I have tried the equivalent using std::list, and again all is fine (with a list of objects or pointers).
Question is, am I trying to do something that is not supported, have I done something obviously wrong, or is this a bug in the STL.net library?
<div class="ForumMod">modified on Wednesday, August 27, 2008 9:38 AM</div>
|
|
|
|
|
I think you need to make ref struct SInside access level "public" due to the usage of generics in STL/CLR. However, if this ref struct SInside is only going to be accessed within the same assembly, you can make it's access level "internal" or "protected public".
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Thursday, August 28, 2008 3:39 PM
|
|
|
|
|
I am connecting Sqlserver2000 with VC++6.0(MFC) and ERROR when update information. please help me. thanks very much
----------------------------------------------------
void CReadDBDlg::OnRead()
{
// TODO: Add your control notification handler code here
CDatabase database;
CString SqlString;
CString sCatID, sCategory;
CString sDriver = "SQL Server";
CString sDsn;
CString sFile = "nhanvien_DATA.mdf";
int iRec = 0;
sDsn.Format("Driver={SQL Server};Server={EZITWK115};" "Trusted_Connection=no;""Database=NHANVIEN;Uid=sa;Pwd=sa;");
TRY
{
// Open the database
database.Open(NULL,FALSE,FALSE,sDsn,TRUE);
// Allocate the recordset
CRecordset recset( &database );
CString SS2 = "UPDATE nhan_vien SET hoten = 'nU' WHERE manv = '002' ";
//Execute query ====>> This is ERROR !!!
recset.Open(CRecordset::forwardOnly,
"{CALL " + SS2 + "}", CRecordset::executeDirect);
// Close the database
database.Close();
}
CATCH(CDBException, e)
{
// If a database exception occured, show error msg
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}
-------------
|
|
|
|
|
PLEASE stop repeatedly posting this question.
There's no managed C++ in VC6 so you're posting in the WRONG PLACE!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I have created and maintain a VC++ .NET 2005 project that creates a dll for SQL server 2000/2005 extended stored proc.
For now it recomplies the source files(originally written in VC++ 6.0) but it required by me to use the existing COM dll written in VS6 from VC++ .NET 2005.
Is it even possible to call Com dll from VC++ .NET 2005?
If yes how can I do that?
I used to program in .NET but haven't done any intensive programming in years, so please if I ask stupid questions.
Please feel free to ask any other info.
Thanks in advance for your help.
-Amit
|
|
|
|
|
amalhotr wrote: Is it even possible to call Com dll from VC++ .NET 2005?
Yes.
amalhotr wrote: I used to program in .NET but haven't done any intensive programming in years
Ok, but are you an experienced C++ developer? If not then you are not prepared to do COM development in C++. First one learns C++, then one learns other things like how to do Win32 COM development.
amalhotr wrote: so please if I ask stupid questions.
There is no such thing as a stupid question. However there are questions posted into the wrong forum. This forum is about doing managed development for the .NET platform using C++/CLI. That does not appear to be what your question is about.
For native C++ questions there is the Visual C++ / MFC forum
For COM questions there is the COM forum
Either one of those would probably have been a more appropriate forum for your question.
led mike
|
|
|
|
|
Thanks for your help.
I'll post it in COM forum.
|
|
|
|
|
Please Guide I command "Update" Sql2000 in VC++6.0.
thanks very much
|
|
|
|
|
I have the same question as the guy below this form, but my question has to do with MDIparents and childs. I followed a guide that told you how to, but I kept getting errors everytime I built it.
http://www.functionx.com/vcnet/Lesson07.htm[^]
I used this guide, but it gave me errors saying its a mix between Managed and nonManaged C++.
I'm new to MDIParents+childs and was wondering if i can get some help with this.
And when i used what you told the guy below me i got these 2 errors.
System.InvalidOperationException: Starting a second message loop on a single thread is not a valid operation. Use Form.ShowDialog instead.
System.InvalidOperationException: Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling Show.
I did what it said both times, but still got same problem.
modified on Sunday, August 24, 2008 11:02 PM
|
|
|
|
|
I don't know what you already tried to do.
But I think it is quite easy to add a MDI child form.
In the MDI-Parent, set IsMdiContainer = true.
And to create a new Child (e.g. from a event handler
within the MDI-Parent):
Child^ child = gcnew Child();
child->MdiParent = this;
child->Visible = true; Alex
|
|
|
|
|
Hi, I need use two forms in application. Is some easy way exists? I do that in Delphi, but in C++/CLI Win Form app is something understandable. I was googling for some easy practise, but not found it.
Is there something who help me with piece of code for two forms?
|
|
|
|
|
you can use multiple forms in C++/CLI. Just right click on your project and click "Add new Item..."
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Sure, but I cant use (in example) in Form1 ->
Form1.Visible = true; OK
Form2.Show = true; it doesnt know Form2
(I maybe use :: )
I must include something to Form1?
|
|
|
|
|
You can create 2 separate forms just as teejayem suggested, but if you want them completely independent of each other (i.e. Form2 is not a child of Form1), then you need to modify your <project_name>.cpp file that opens your main form. This file contains your main loop, and probably has a line like
Application::Run(gcnew Form1());
You would need to change this to create your Form1 and Form2 objects, show them, and then start your application. You might need a DoEvents loop, but there might be a way around that.
Dybs
|
|
|
|
|
You have to include the form2.h in your form1.h file for you to be able to use it
#include "Form2.h"
also "Show" isn't a property, it is a method. You shouldn't be trying to assign a boolean to it
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Thank you, it works, but there is still little problem.
Form1::Visible = false;<br />
<br />
<br />
Form2->Show();
|
|
|
|
|
I'm guessing that is because your varaible name is the same as your class name. so the compiler is thinking your trying to call a static method. Change your variable name to something more unique
System::Windows::Forms::Form^ myFrm2 = gcnew System::Windows::Forms::Form()
myFrm2->Show()
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Oh, thank you for your help. I was googling with "c++\cli" AND "#include"Form2.h"" and I found solution. It was that what you wrote. Same name Form2. THANK YOU
modified on Sunday, August 24, 2008 1:43 PM
|
|
|
|
|
I need a simple example on how to use OpenFileDialog(). I don't want to extend it or enhance it (I did search for articles), just use it. Even after searching the entire Visual Studio directory, I cannot find the right files to include so that the compile stops telling me that OpenFileDialog is an undeclared identifier.
Do you have a link that will help me out?
Thank you.
Thanks for your time
|
|
|
|
|
example
to use this class you need to include the System.Windows.Forms assembly and add the namespace on top of your .h
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hello teejayem,
I feel like there are too many questions to ask. I check your example link, but Microsoft leaves so much out and is so different from my code that I don’t understand it.
RE: to use this class you need to include the System.Windows.Forms assembly and add the namespace on top of your .h
Does this mean to put the below at the top of my .h file?
#include “System.Windows.Forms”
using System.Windows.Forms
The on button function in my code, created by VS, starts like this:
void Ctest1Dlg::OnBnClickedSelectLogFileButton()
{
And does not look anything like the example code:
void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
I read about the ^ character and still don’t make any sense of that.
I wonder why we need more obscure characters in C++. It seems like we are trying to turn C++ into APL.
And just to be certain, I am using Visual Studio 2008 under Windows XP Home.
Thanks for your time
|
|
|
|
|
"RE: to use this class you need to include the System.Windows.Forms assembly and add the namespace on top of your .h"
you need to add the namespace like:
using namespace System::Windows::Forms;
"I read about the ^ character and still don’t make any sense of that."
"In C++/CLI the only type of pointer is the normal C++ pointer, and the .NET reference types are accessed through a "handle", with the new syntax ClassName^ instead of ClassName*"
Source[^]
"I wonder why we need more obscure characters in C++. It seems like we are trying to turn C++ into APL."
Hopefully you are talking about C++/CLI and not pure C++! You cannot use managed classes in a pure C++ application.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
bkelly13 wrote: I wonder why we need more obscure characters in C++. It seems like we are trying to turn C++ into APL.
C++/CLI should be treated as a separate language.
C++ is still C++. No obscure characters have been added.
Are you sure C++/CLI is what you want to use? There's also
a way to use the open file common dialog from native C++.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|