|
Doug if you are still having a problem you might want to read this[^]
article from MSDN, especially the remarks.
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
Thanks everyone, problem solved!;)
Doug
|
|
|
|
|
Hi Nick
Re: ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable
I have found the source of the problem expressed in the thread "ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable":
http://www.codeproject.com/script/comments/forums.asp?forumid=3785#xx309754xx
but do not yet know why it occurs or how I can fix it.
The problem arises with the /clr compiler setting.
Here is the code to illustrate this:
/////////////////////////////////////////////////////////
#include <stdafx.h>
#include <cstdlib>
#include "try_ADONET.h"
//#using <mscorlib.dll>
//#using <system.dll>
//#using <system.data.dll> // This is required for the ADO.NET Provider
using namespace std;
//using namespace System;
int Main()
{
CString busNumberSQL[2];
CString bus = "Hello";
busNumberSQL[1] = bus;
return 0;
}
////////////////////////////////////////////////////////
Without the /clr setting the array of CString busNumberSQL[2] is correctly contructed as is CString bus and the line
busNumberSQL[1] = bus;
works as expected. This can be seen by putting a breakpoint in at
return 0;
and seeing the variables in a Watch. Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet.
..................
Next, add the compiler switch /clr and rerun the code.
CString bus is constructed correctly BUT something weird happens in the construction of CString busNumberSQL[2].
Now,
busNumberSQL[1] = bus;
results in the address of bus as an integer being assigned to busNumberSQL[1], and look at the Watch details!!
Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet
Name: busNumberSQL; Value: {Length=2}; Type: ATL::CStringT<char,strtraitmfc<char,atl::chtraitscrt<char> > >[] ...(Note no dimension at end compared to the "no /clr" case.
Next Watch line: [0] 2083454756 __int32
Next Watch line: [1] 3103464 __int32
My conclusion is that busNumberSQL[2] is not an array of CString.
Of course, I need the /clr in order to use ADO.NET!
It seems as though a CString works, but a CString array for some (unknown) cannot even be defined.
Do you have any light for me? (I have not got into your previous post yet on Marshall)
Best regards
Doug.
(In case you are wondering I am very much a beginner with C++ and .NET)
Doug
|
|
|
|
|
Thanks Nish,
I have definitely got this working where the native C++ type is int and I am confident that I can now handle any numeric type.
What I am battling with is where the .NET value retrieved is a String (the SQL field is text).
I have managed to get the following to work:
String* busNumberSQL __gc[] = new String* __gc[97];
short halfhoursSQL = 0;
.
.
.
Console::WriteLine(myReader->GetString(0));
halfhoursSQL++;
busNumberSQL[halfhoursSQL] = Convert::ToString(myReader->GetValue(0));
However busNumberSQL is a managed array of type String*.
Now I need assign the value of busNumberSQL[halfhoursSQL] to a CString or native C++ string type. All I seem to end up with is the decimal representation of the hexidecimal memory address.
I have also tried:
Convert::ToChar(myReader->GetValue(0)) to assign one character
(Convert::ToString(myReader->GetValue(0)))->ToCharArray()
As I continue to try different things, do you have any idea how this may be done? I will let you know if I crack it.
(With the old ADO I was able to do this by doing a double cast: ---> _bstr_t --> LPCTSTR and then doing a simple assignment to a CString)
Thanks and regards
Doug
Doug
|
|
|
|
|
Hi Nish
Re: ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable
I have found the source of the problem expressed in the thread "ADO.NET : SqlDataReader : I need to assign retrieved value to C++ variable":
http://www.codeproject.com/script/comments/forums.asp?forumid=3785#xx309754xx
but do not yet know why it occurs or how I can fix it.
The problem arises with the /clr compiler setting.
Here is the code to illustrate this:
/////////////////////////////////////////////////////////
#include <stdafx.h>
#include <cstdlib>
#include "try_ADONET.h"
//#using <mscorlib.dll>
//#using <system.dll>
//#using <system.data.dll> // This is required for the ADO.NET Provider
using namespace std;
//using namespace System;
int Main()
{
CString busNumberSQL[2];
CString bus = "Hello";
busNumberSQL[1] = bus;
return 0;
}
////////////////////////////////////////////////////////
Without the /clr setting the array of CString busNumberSQL[2] is correctly contructed as is CString bus and the line
busNumberSQL[1] = bus;
works as expected. This can be seen by putting a breakpoint in at
return 0;
and seeing the variables in a Watch. Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet.
..................
Next, add the compiler switch /clr and rerun the code.
CString bus is constructed correctly BUT something weird happens in the construction of CString busNumberSQL[2].
Now,
busNumberSQL[1] = bus;
results in the address of bus as an integer being assigned to busNumberSQL[1], and look at the Watch details!!
Copy the expanded Watch details (Name, Value & Type) to an EXCEL sheet
Name: busNumberSQL; Value: {Length=2}; Type: ATL::CStringT<char,strtraitmfc<char,atl::chtraitscrt<char> > >[] ...(Note no dimension at end compared to the "no /clr" case.
Next Watch line: [0] 2083454756 __int32
Next Watch line: [1] 3103464 __int32
My conclusion is that busNumberSQL[2] is not an array of CString.
Of course, I need the /clr in order to use ADO.NET!
It seems as though a CString works, but a CString array for some (unknown) cannot even be defined.
Do you have any light for me? (I have not got into your previous post yet on Marshall)
Best regards
Doug.
(In case you are wondering I am very much a beginner with C++ and .NET)
Doug
|
|
|
|
|
I'm using a purchased unmanaged library that controls some hardware and throws a windows event (returning an event HANDLE)when the hardware is ready. I'd like to use this event to update my windows form. Is there any way to marshall the event HANDLE to a .NET event?
|
|
|
|
|
Hi.
I want to use WMI functions in a managed C++ project. I have found these functions and classes are defined in the wbemdisp.tlb, but I have not managed to include this library in my class.
In VB.NET I just had to add a reference to the library, so I ought to be possible in C++ as well, but how?
Best regards
/EnkelIk
|
|
|
|
|
See System::Management namespace. It wraps WMI.
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
Hi.
I have created an application starting with a "Managed C++ empty project". Now I would want the users to be able to run this project from a local server and therefore need their .NET frameworks to trust the application.
How do I make my project an assembly? I tried just adding an AssemblyInfo.cpp file to my project and generating a keyfile, but that did of course not do the trick. Using the Microsoft .NET framework wizard, it does not recognize the *.exe as an Assembly. What more do I need to do?
Regards
/EnkelIk
|
|
|
|
|
I just realized that even if I create a Managed C++ Application project and get the AssemblyInfo file automatically generated I still get the error "Unable to load assembly ....." when I try to set "Trust an assembly" in the .net wizards. If I try with a dll though everything works fine.
What am I doing wrong? The only thing I did after having created the Managed C++ application as well as the Managed C++ class library was to compile them. I've tried adding a strong name key but that did not help.
All help will, as always, be greatly appreciated.
/EnkelIk
|
|
|
|
|
how to creat a setup project that will install an application through a wizerd ?
how to creat DNS programatically (driver name that we manually make in DB projects)?
how to logoff and login programatically ?
r00d0034@yahoo.com
|
|
|
|
|
There are some companies that provides such programs.But i don't know how and where they can be found.
|
|
|
|
|
Hi Guys,
How can I add STL lib in MC++?
Thanks
|
|
|
|
|
You just include the header files and use it as if you were writing a standard C++ application. There's nothing special about it.
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|
Hi.
I'm using a TextBox to display status messages to the user (like:
"Retrieving MAC address: 002345235cbd"
"Retrieving IP-number: 10.10.10.10"
and so on). The messages are added line by line so that the first message is never over written. The only way I have found to be able to control when to get a new line is to use a String array and the set_Lines method, since neither \n, \v or \f has the desired effect. Is there no better way?
The main problem using the TextBox->set_Lines method is that all the lines are set at the same time so I can't have different fontstyle on different lines.
Anyone has a solution? Or should I use something else than TextBox to display the messages? If so what?
Regards
/EnkelIk
|
|
|
|
|
Environment.NewLine is the .NET friendly way to make something multiline, and make sure the text control is set to multiline also.
Christian
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Yes, I can't find a better way than using strings and then doing something like:
String* break="\r\n";
String::Concat(textString1,break,textString2);
This is obviously a lousy solution because you have to put all of your strings together before you even display them!
MS says that we shouldn't even be using strings anymore if they have to be manipulated repeatedly, but should use stringBuilder instead. Unfortunately, stringBuilder has been proven in clinical trials to cause insanity in 3 out of 5 users.
|
|
|
|
|
this line of code
IFormatter formatter = new BinaryFormatter();Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);formatter.Serialize(stream, obj);stream.Close();
alwas write data at the end of file or not ?
i mean there are alot of Objects .
where it write in the file?
this line of code
object obj = formatter.Deserialize(stream);
alwas read data from the begining of file or not ?
i mean there are alot of Objects.
where it read from the file?
r00d0034@yahoo.com
|
|
|
|
|
HOW to creat FileStream object that coud write into a file ?
can you explain any of its constructor?
how to write data using FileStream into a file or read theobject from a file to the FileStream object only then it is possible to serialize or Deserialize it?
i want to write a hastable object into a file that contain class objects,and class objects further contain hashtable and other class objects.
may i write that hashtable into a file and retrive again?
i study the api but could not understand what methods to use.
r00d0034@yahoo.com
|
|
|
|
|
if i have a class like
public __gc class{
String *str;
int a ;
}
i want to right its object into file.after that i want to send it to different computer through network and again want to read it again if i have the same class there may i read it into that class object.
is it possible ?
can any body write the syntex of reading and writing the object ito a file ?
r00d0034@yahoo.com
|
|
|
|
|
i want to write its object into a file and send that file through a network to different computer and i want to recive that object again if i have the same class there.
may i read the same object on network from a file?
any body can explain my idea into code like
how to write object into file ?
how to read object on the network (having same class there) from file ?
r00d0034@yahoo.com
|
|
|
|
|
I n how many forums are you going to ask this!
Learn one thing: C++ questions belongs to the Visual C++ forum!!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
i think there is a class in dot net also and object are also created in csharp?
i think thats a language independent question.
r00d0034@yahoo.com
|
|
|
|
|
how to use OutputDebugString in managed code?
r00d0034@yahoo.com
|
|
|
|
|
From Managed C++ you can include windows.h and then just call the function as you normally would.
This will make use of the "IJW" or "it just works" interoperability feature of Managed C++.
The following page has additional information on this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp
Hope this helps!
Tarek Madkour & Mark Lacey
Microsoft Visual C++ Team
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|