|
Hi,
I might be wrong but most likely you forgot to initialize your array.
testlib::testlibControl *tmp1 __gc[];
// add the following
tmp1 = __gc new testlib::testlibControl*[strength];
for(int i = 0; i < strength; i++)
{
...
However with the new Syntax it should be something like this:
array<testlib::testlibControl^>^ tmp1 = gcnew array<testlib::testlibControl^>(strength);
Furthermore i do strongly recommend to use the new syntax, because it is far more easy to read.
best regards Tobias
|
|
|
|
|
ok .. i've made required changes as follows but still i'm getting the
same exception
testlib::testlibControl *tmp1 __gc [];
tmp1 = new testlib::testlibControl* __gc [10];
for(int i = 0; i < strength; i++)
{
tmp1[i]->Location = System::Drawing::Point(x,y); //exception
....
...
}
Thanks,
Kranti
|
|
|
|
|
Hmm,
is it correct that your testlibcontrol class is unmanaged?
I mean, as far as i know it should be like this if it's a managed one:
testlib::testlibControl __gc* tmp1 __gc [];
Though i suppose you have created a managed array of unmanaged testlibcontrol pointers? However you said that it is crashing on this line:
tmp1[i]->Location = System::Drawing::Point(x,y); //exception
Therefore it can be only one of the two things, either x or y have not been initialized (which is very unlikely) or your array is not properly initialized. IMHO it is related to the second one. Therefore I would suggest that you'll have a close look into your testlibcontrol class (constructor etc.) and the initialization of that array again. Furthermore you should step through your code with the debugger and check if it has really initialized an object of the type testlibcontrol here:
tmp1[i] = new testlib::testlibControl;
regards Tobias
|
|
|
|
|
hey,
thanks a lot .. this type of initialization worked for me ...
testlib::testlibControl *tmp1[] = __gc new testlib::testlibControl*[10];
tmp1[i] = new testlib::testlibControl;
tmp1[i]->Location = System::Drawing::Point(x,y);
tmp1[i]->Size = System::Drawing::Size(24, 29);
Thanks,
Kranti
|
|
|
|
|
How to write and read an object of user defined class into file.
|
|
|
|
|
this is called serialization.
i think that if you posted your question here, it's because you'd like to do it in Managed C++.
i don't have the solution, but there is certainly some articles about how to Serialize/Deserialize class instances.
|
|
|
|
|
I am using Borland C++ (v4.5) and trying to write a program to input output one byte to the parallel port. It used to be fairly easy prior to XP. I have seen various things on the web that are supposed to get around the hard bit of overriding XP's control over the port, e.g.
www.geekhideout.com/iodll.shtml
but I can't get them to work. I think I must be doing something wrong in the way I include the .h and .dll files into the project. What is the difference between starting an ordinary .cpp program and a project.
Can anybody offer me some advice please
Geoff
|
|
|
|
|
|
I am currently using Visual Studio 2003, I see that when I choose a new project for C++ I can not pick any project to develop on a mobile device. C# has this option.
Is it possible to build an application in C++ with managed extension (with \clr ) for mobile development? If so does anybody got a link or so to point me in the right direction?
Greetings,
Davy
|
|
|
|
|
hi everyone i have a project like that :
You are supposed to develop a garage system simulator. Possible system classes are car owner, car, garage, fee, payment.
Take into account the following assumptions:
1- A customer may take parking , washing, polishing services.
2- There is predefined parking fee list. Important point is to hold time chart for a car.
3- Washing service choices are outer or all.
4- Payment includes all services.
5- Manager should be able to check the numbers of car and the money. This report may be taken daily or for a duration.
please help.
if you write c++ code i will be so presuade. thanks a lot.
-- modified at 11:50 Tuesday 4th April, 2006
|
|
|
|
|
Sir,
You need to start writing your simulator application. While you are programming and you have a specific question on coding, please post your question here if you are using Managed C++ or C++/CLI. Otherwise, not too many developers are "nice" enough to write this project for you.
George
-- modified at 18:45 Tuesday 4th April, 2006
|
|
|
|
|
do your homework yourself
|
|
|
|
|
Did you read this[^] before posting ?
-- modified at 5:08 Wednesday 5th April, 2006
Link corrected
|
|
|
|
|
ok guys, i will start my project and if i have a specific question i will ask it. thanks a lot.
|
|
|
|
|
I`m writing a dll in C++ that uses managed extensions. Its purpose is to wrap a .NET library I wrote so that I can use it in an existing C++ project I have here.
All goes smooth, but I got some problems now calling a C# function of the dll that has an out parameter.
function definition in C#:
public enumMsgType DoYourThing(string sMethod, ref Single Cnt, out string outParam, string inParam)
my wrapper function is:
CMyWrapperObj::wrMessageType CMyWrapperObj::InvokeMethod( LPCTSTR sMethod, float& nNum1, CString& sOutParam, LPCTSTR sInParam)<br />
{<br />
return static_cast<CMyWrapperObj::wrMessageType>((*this)->InvokeMethod(sMethod, &nNum1, sOutParam,sInParam));<br />
}<br />
I get a build error on the sOutParam parameter:
MyWrapper.cpp(60) : error C2664: 'COMCaller::ManagedObj::DoYourThing' : cannot convert parameter 3 from 'CString' to 'System::String __gc *__gc * '
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
So I guess I need to call this function not with a CString parameter.. .I also tried a std::string variable to pass in the parameter list, but also that doesn^t work... It`s probably something obveous that I`m overlooking, but if you could point me to it I would be gratefull
Greetings,
Davy
|
|
|
|
|
why don't you use LPCTSTR parameter, or ever simple, System::String ?
|
|
|
|
|
LPCTSTR because the string isn^t a constant, it will get a new value in the .NET function that will be called.
System::String .. Since I don^t want to have any managed types in my header files I guess my mind didn^t get to that point.
Well thanks a lot, got the thing compiled now, I can now focus on the next issue!
|
|
|
|
|
Hi,
I've to write a query which requires a function similar to "sprintf" in C
For e.g.
String *query; // in c++.net
sprintf(query, "Select * from table_name where number = %d", no); // in C
How can this be done in this environment?
Thanks,
Kranti
|
|
|
|
|
Kranti1251984 wrote: I've to write a query which requires a function similar to "sprintf" in C
For e.g.
String *query; // in c++.net
sprintf(query, "Select * from table_name where number = %d", no); // in C
How can this be done in this environment?
Hi Kranti1251984,
yes, there is actually. For instance you could use:
System::String::Format(...)
<br />
String^ s = String::Format(<br />
"(C) Currency: . . . . . . . . {0:C}\n" +<br />
"(D) Decimal:. . . . . . . . . {0:D}\n" +<br />
"(E) Scientific: . . . . . . . {1:E}\n" +<br />
"(F) Fixed point:. . . . . . . {1:F}\n" +<br />
"(G) General:. . . . . . . . . {0:G}\n" +<br />
" (default):. . . . . . . . {0} (default = 'G')\n" +<br />
"(N) Number: . . . . . . . . . {0:N}\n" +<br />
"(P) Percent:. . . . . . . . . {1:P}\n" +<br />
"(R) Round-trip: . . . . . . . {1:R}\n" +<br />
"(X) Hexadecimal:. . . . . . . {0:X}\n",<br />
-123, -123.45f); <br />
Console::WriteLine(s);<br />
In addition i would like to point out, that it would be more secure to use parameters when constructing dynamic SQL statements.
best regards Tobias
|
|
|
|
|
2beeIn addition i would like to point out, that it would be more secure to use parameters when constructing dynamic SQL statements.
Just to add to Tobias' quoted comment, SQL Injection can be a big problem. For instance, a user can "inject" a DELETE statement into your programmically built SQL string and do some serious damage. Using parameters, SQL injection is impossible.
|
|
|
|
|
Hello,
Is it possible to include a .dll in a /clr:pure project?
I am currently using unmanaged code for this.
I was wondering if it is also possible with a /clr:pure project which does not allow native C++?
Including a .dll can be done with C#.
(Full setting is "Pure MSIL Common Language Runtime Support (/clr:pure)" in the project properties -> General)
best regards,
Jan Timmerman
|
|
|
|
|
What do you mean by 'include a dll'?
If ur question is whether an unmanaged dll can be used in a /clr:pure c++/cli project, Yes, You can do. Inlcude the lib and header file to c++/cli project and you can create objects of unmanaged clasees in the dll or u can call unmanaged functions in that dll.
You can use a com dll as well using the #import
c++/cli is the only language where u can mix both managed unmanaged code.
deoes this make sense...mil10.
|
|
|
|
|
Thanks for your reply:
Well that was about where I was aiming at.
I never heard of the "#import" directive before so I will have to look into that. I have not too much experience with Visual studio.
Perhaps I should explain a little more about the situation.
Currently I have a ".lib" and a ".dll" generated by Compaq Visual Fortran.
I've declared the function called from the .dll as follows:
<br />
extern "C" void __declspec(dllimport) extiteratie( [arguments] )<br />
First I get the warning:
<br />
TFortranInterface.cpp(27) : warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify native calling convention when importing a function.<br />
after that an error
<br />
error LNK2031: unable to generate p/invoke for "extern "C" void __clrcall extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata<br />
(After this an unresolved token error which is most likely caused by the previous error.)
I am currently using a native class as interface because I need to pass the function in the .dll a set of pointers which will be filled with results.
The questions:
1. With /clr:pure I cannot use that native class?
2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?)
(3. what does #import do?)
best regards,
Jan Timmerman
|
|
|
|
|
1. With /clr:pure I cannot use that native class?
Yes, You can use native class in a /clr:pure c++/cli project.
2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?)
Note the warning you got: "warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify native calling convention when importing a function."
Your function declaration was:
extern "C" void __declspec(dllimport) extiteratie( [arguments] ) : Here you havn't mentioned any calling convention. So compiler took the clr only calling convention __clrcall . Now see the error message you got - "error LNK2031: unable to generate p/invoke for "extern "C" void __clrcall extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata"
This means that C++/CLI compiler is not able to generate the p/invoke for a function which is reserverd for CLI only (because of the by default __clrcall calling convention).
So to fix this, change the function declaration as below:
extern "C" void __stdcall __declspec(dllimport) extiteratie( [arguments] )
Here if the calling convention of extiteratie is soemthing else other than __stdcall , then put the same instaed.
3. what does #import do?)
You dont have to worry abt #import as ur dll is not a com dll. It is for using com components.
Hope this will help...mil10.
|
|
|
|
|
Great, it works!
i've modified the function call to
<br />
extern "C" void __cdecl extiteratie( [arguments] )
(from the error messages I noticed the compiler ignores the "__declspec(dllimport)" part when including __cdecl)
Also I added an underscore to the function export in the Fortran code which was needed by __cdecl.
An alternative is (most likely but not tested) to use __stdcall in the export. I do not think it makes much difference whether I use __stdcall or __cdecl?
Thanks a lot!
Jan Timmerman
|
|
|
|