|
Mark you just made my day! Thank you for your help. Your explanation was awesome, and yes it makes a lot sense about ref and value classes to define them class and structure respectively comparing with VB.Net. Thank you for your help very much!!!
|
|
|
|
|
Hey again, gang,
Once again, I have a question that I'm sure comes from me just missing something simple. I googled around a bit for this, but wasn't able to find anything that addressed this directly, just related tasks that didn't quite give me what I needed. If I'm just being thick-headed, I'd be more than happy with just being slapped with a link so I can learn on my own.
I'm dealing with a large collection of .h and .cpp files that together make up a bunch of classes that assist with TCP communication for a large project. Several different programs in the project use these files, and they currently do so by just #include-ing them in their own code. Consequently, a change to one packet class makes it necessary to recompile every project that depends on it. I believe that it would be better to roll all of these files into a DLL that each of the other projects can link against.
I have written my own DLLs a few times, but have always done so by creating a namespace in the DLL project and adding classes to it directly, but I can't do that here since the classes are already defined in the existing headers. How can I include these existing classes in my DLL project and make them visible from its namespace? Just #include-ing them doesn't seem to be enough, since I get a bundle of linker errors when I try to use the resulting DLL in other projects.
Could someone please clue me in or point me to a resource on this? Thanks a million!
(I'm using Visual Studio 2008 with C++/CLI. The code I'm trying to roll up is written in C++, and is cross-platform enough to be compiled on Windows and Linux boxes. I'm trying to create a DLL out of them to be used in other C++/CLI projects, and let the Linux guys handle it their own way on their side, so I don't want to modify the existing code and make it Windows-only.)
|
|
|
|
|
|
I did think my goal was to create a .NET assembly, but perhaps I was wrong about that as well. If that is the case, I'm very sorry that I put this up in the wrong place. I hate being the forum dolt.
I need to study the links you provided a little more closely to be sure, but it does look like that is the information I need. If I can figure out how to use dllexport to expose a class outside of the DLL, I'll be set.
Thank you very much for the lead, Mike. (Har!)
|
|
|
|
|
I am Using Visual c++ 2005
I need to make ab choice of all my Printing options
I have a Problem how to fill into my comBobox All Orientation Parper
I try This
this->paperorientation->DataSource = System::Enum::GetValues(GetType(PaperOrientation))
I have a message CrystalDecisions::Shared::PaperOrientation: Illegal use of this type as an expression.
I do not what to do
Can you help me
I need to fill my Paper Orientation, PAper Size, Paper Duplex ComboBoxes
Help needed
|
|
|
|
|
Hello,
I want to use RAR compression in my MC++ project ...
Please help me.
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
Have you tried googling around?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
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();
|
|
|
|