|
Nope. Library should be compiled only once and it should be a mixed mode DLL (compiled using /clr ). Trick is with header files. When a native user uses your library, he will see only the methods defined for native. Other methods are not seen as those are guarded with _MANAGED preprocessor directive.
1 - You create the library with exported functions and managed wrapper functions. This should be compiled with /clr switch.
2 - Supply the library along with header file. Since header file has preprocessor statements, managed method definitions won't be seen by a native compiler. They still can work with native methods.
Since your DLL is mixed mode, all users require .NET framework to be installed of course.
|
|
|
|
|
- using visual studio 2008 -
what i have done so far is this:
a) i selected the file .lib and the .h and imported in my project -- done
b) i set in the project properties the linker to point to the lib file --done
c) i set in the project properties the c++ to look for the .h file --done
d) i set in the general project properties to compile using clr
e) my portion of code where i inlude the .h:
...
#pragma unmanaged
#include "database.h"
#pragma managed
...
f) i put a button in my form and onclick i initialize a class in the unmanaged class
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
db::database db2;
}
catch (System::Exception ^exception) {
}
}
g) after that i compile and everything goes fine (i thinked "maybe too simple")
h) i run the application and ....tada error...
An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module.
Additional information: The type initializer for '<Module>' threw an exception.
i googled around and i see is a common problem but i can't find an answer on what i have a todo...a magic code like #pragma something or some compiler settings or somethings....i neither find a good "howTo" on how to do this... can someone help me out or point me to a tutorial - how to ?? thx
modified on Thursday, October 1, 2009 8:02 AM
|
|
|
|
|
maybe the question was to general...i make a link where you can download my sample file with the problem. Th warnings are only because of my lib was for 'release' only. Hope someone can help me.
link
ps you need to correct the path of the linker to where you have the project to get the lib
ps2 maybe you need mysql do be installed on your pc with developer option to use because it use a mysql dll to run
or you have to put this dll in the project folder and you'll get it--download--
modified on Thursday, October 1, 2009 8:24 AM
|
|
|
|
|
carlo.andreoli wrote: you can download my sample file with the problem
This looks like a fairly sizeable project, the zip file is nearly 5Mb. I think you are going to have to do some more work in narrowing down exactly where the error is occurring, at least to the line of code in your source.
|
|
|
|
|
ok if you open the program you'll see the real program are something like 100 line of real code. the size is beacuse i include all the vc++ project including the 2 lib that's like ~10MB of code...but the lib already work. The problem is that i compile it and everything goes right. When i run it gives me the error, the problem is in including the unmanaged class and trying to use it. It give me the error before i could initialize the first unmanaged class. Pls give it a try it's only 100 lines of code
|
|
|
|
|
carlo.andreoli wrote: Pls give it a try it's only 100 lines of code
Well I guess it's not too big a task for you then. You have all the same tools that I have to debug this; also you understand your code, I don't.
|
|
|
|
|
I have taken a look at your project, and in the button click event I see
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
try {
db::database db2;
}
catch (System::Exception ^exception) {
}
This does not agree with your original description. I also found that the project will not link under VC++ Express Edition, as the library appears to have been built with VS 2008, which I do not possess.
|
|
|
|
|
i'm currently working with visual studio 2008 express edition. Why the coode doesn't agree with my original description ?(maybe i used different variabiles name but that was just an example, i'm going to correct it). pls help me point out. Now i give you all the things i have done:
1) we want to develop an application that can speak with database
2) i am making the visual side of the project using visual studio 2008 express
3) my friend is developing the 'wrapper' to connect to mysql but it's developing not in vs2008 express edition
4) now i want to integrate his code with mine
5) i take his code and if i make a program (without using clr) it works fine
6) i take his code and put it on a form, using clr option to compile,it compiles well but then it crash giving me the error you see in the starter thread
any ideas...do i have to be more specific?
thx man i really want to understand where is the problem and you are trying to help me
ps you need to correct the path of the linker to where you have the project to get the lib
ps2 maybe you need mysql do be installed on your pc with developer option to use because it use a mysql dll to run
or --> you have to put this dll in the project folder and you'll get it--download--
modified on Thursday, October 1, 2009 8:24 AM
|
|
|
|
|
carlo.andreoli wrote: 6) i take his code and put it on a form, using clr option to compile,it compiles well but then it crash giving me the error you see in the starter thread
Well, as I stated before, you have all the tools to track down where it is failing. Use the debugger, step through the program to the fail point and then look at the variables and stack trace to see what is going on. If the problem lies in your friend's library then get him to fix it.
|
|
|
|
|
i'll give it a try...but i'm new to c++ programming..i have only developed thing through application by now so i have to skill a lot. Now i'll try to look at the stack frame to see if i can understand something
|
|
|
|
|
carlo.andreoli wrote: i'll give it a try...but i'm new to c++ programming
Maybe you should have started with a simpler project! Learning C++ is not the easiest task, even for programmers coming from C or Pascal background. You made it even harder by going for the managed C++/CLI form which adds a whole extra level of complexity. Buona fortuna!
|
|
|
|
|
Hello Everyone, I am struggling with a problem for two days and could not figure out what to do.
Here what I am trying to do.
I have cli<array> which is two dimentional. I get data in that array but is not in order. I want to copy that data in a temp array [same type] in order. I want change the location of the column and put it indore to the temp array.
example,original array A[0,0]
A[0,1]
A[0,2]
A[0,3]
I want to copy column in a different location of the new array
B[0,0]=A[0,2]
B[0,1]=A[0,3]
B[0,2]=A[0,0]
B[0,3]= A[0,0];
If anybody can please give me a hint would be very helpful.
if you did not understand the question please ask me I really need it soon.
Thanks in advance.
|
|
|
|
|
What specific problem are you facing here?
|
|
|
|
|
Hi Navaneeth, Sorry to answer you late but thanks for your kindness.
the question I have is I want to copy a two dimentional array but not just a carbon copy. I want to get what ever index I want and insert into a new array.
for example, array A has 10 index and I want to copy array A to Array B but not same order.array A's index 1,3,6,8 I want it to be array B's index 1,2,3,4.
how do I do this.
Sorry question may trivial but I need to know it since I am not a expert yet.
thanks
Jashim
|
|
|
|
|
jashimu wrote: I want to copy column in a different location of the new array
B[0,0]=A[0,2]
B[0,1]=A[0,3]
B[0,2]=A[0,0]
B[0,3]= A[0,0];
I think this is your only solution, since there appears to be no logical order to your input data.
|
|
|
|
|
I figure it out the same. I did manually everything.
thanks for your reply Richard.
jashim
|
|
|
|
|
googling around i found some extension to the default tiempicker to make backcolor suitable...what i have till now is:
namespace primoAlpha {
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Security::Permissions;
public ref class extendedDateTimePicker : DateTimePicker
{
private:
Color _BackColor;
public:
property Color BackColor
{
virtual Color get() override {
return _BackColor;
}
virtual void set(Color value) override {
_BackColor = value;
Invalidate();
}
}
protected:
[SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
virtual void WndProc( Message% m ) override
{
if ( m.Msg == (int) 0x0014 ) {
Graphics ^g = Graphics::FromHdc(m.WParam);
g->FillRectangle(gcnew SolidBrush(_BackColor),
ClientRectangle);
g->ReleaseHdc();
return;
}
WndProc(m);
}
};
}
the code compile with no error but when i run it gives me an
"An unhandled exception of type 'System.StackOverflowException' occurred in primoAlpha.exe"
any help is really apprecieted, i'm a noob in c++
|
|
|
|
|
Hi,
IMO your WndProc is calling itself instead of the base WndProc method. I don't know the correct C++/CLI syntax for it though.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
the code from which i constrcuted the code tell to use
Form::WndProc(m);
but if try to use it it tell me "candidate function(s) not accessible"
cause Form::WndProc is a private code.
|
|
|
|
|
it works in C#:
public class extendedDateTimePicker : DateTimePicker {
protected override void WndProc(ref Message m) {
base.WndProc(ref m);
}
}
BTW: the message parameter takes a reference.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc Pattyn wrote: the message parameter takes a reference.
Do you have any idea why it is passed as reference?
|
|
|
|
|
the message is a struct you may want to modify and pass on.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Ahh. That was simple. I was not aware that Message is a struct.
Thanks
|
|
|
|
|
With the number of messages flying around in Windows, they'd better be structs.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Correct syntax is BaseClassName::MethodName . So you write DateTimePicker::WndProc(m) .
public ref class extendedDateTimePicker : DateTimePicker
{
protected:
[SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
virtual void WndProc( Message% m ) override
{
if ( m.Msg == (int) 0x0014 ) { }
DateTimePicker::WndProc(m);
}
};
|
|
|
|