|
To convert String to char*, use the function c_str(). This function will return a const pointer to a regular C string(which will be identical to the passed in string).
std::string Test1 = "Text to Test";
char *Test = Test1.c_str();
Regards,
Rane
|
|
|
|
|
as per my knowledge System::String doesn't have c_str() function , though std::string generally have.. also it return const char*
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
Hi,
You cant use c_str() in CString.
You have to use this function to convert a CString to a char *
char* ConvertToChar(const CString &s)
{
int nSize = s.GetLength();
char *pAnsiString = new char[nSize+1];
memset(pAnsiString,0,nSize+1);
wcstombs(pAnsiString, s, nSize+1);
return pAnsiString;
}
All the best...
The price of anything is the amount of life you exchange for it.
Thanks and Regards.
SANTHOSH V
|
|
|
|
|
if you are using CString there is a method called GetBuffer()
CString s;
char *ch = s.GetBuffer(s.GetLength())
May be it will solve your problem.
plz feedback if you solve it.
|
|
|
|
|
onlyjaypatel wrote: if you are using CString there is a method called GetBuffer()
What ? GetBuffer is the worst thing you can call to do that. CString provides an operator to do the casting, so if it doesn't work, GetBuffer won't work neither. Also, if you do not call ReleaseBuffer later, your CString object can be corrupted. Please, read this[^].
|
|
|
|
|
Which kind of string are you talking about ? CString (from the MFC) or std::string (from the STL) ? You probably have UNICODE define, that's probably why you can't 'convert'. I highly suggest that you read this excellent article[^], things will be much clearer afterwards.
Shirani wrote: when i add data member as String or String^
Are you using managed C++ ? If yes, then this is the wrong forum. This forum is for C++ only, not managed.
|
|
|
|
|
Cedric Moonen wrote:
Are you using managed C++ ? If yes, then this is the wrong forum. This forum is for C++ only, not managed.
atleast somebody have sharp common sense here [ ]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
this is managed c++ related query and it should be asked in it particular section!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
I am looking for code for an interpolation of x,y pairs
y=f(x), linear, polynomial, spline all O.K.
Thanks
|
|
|
|
|
mrby123 wrote: I am looking for code for an interpolation of x,y pairs
y=f(x), linear, polynomial, spline all O.K.
Please try googling first, also as per my knowledge interpolation formula is easy to implements (some , not all ) .. try it
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
In the MSDN, CToolBarCtrl help file is below.
To use a CToolBarCtrl object, you will typically follow these steps:
1. Construct the CToolBarCtrl object.
2. Call Create to create the Windows toolbar common control and attach it to the CToolBarCtrl object. Indicate the style of toolbar by using styles, such as TBSTYLE_TRANSPARENT for a transparent toolbar or TBSTYLE_DROPDOWN for a toolbar that supports drop-down style buttons.
3. Identify how you want the buttons on the toolbar displayed:
(1)•To use bitmap images for buttons, add the button bitmaps to the toolbar by calling AddBitmap.
(2)•To use images displayed from an image list for buttons, specify the image list by calling SetImageList, SetHotImageList, or SetDisabledImageList.
(3)•To use string labels for buttons, add the strings to the toolbar by calling AddString and/or AddStrings.
I don't understand step 3, (1),(2),(3) I could use either one of it(like only use (2)only), or I can use (2) and (3) together.
Sorry for not fully understanding to read the MSDN.
|
|
|
|
|
I have a multithreaded app that has been successfully using CAsyncSockets to talk to non windows sockets for some time. I have also created CAsyncSockets in their own threads to talk to other instances of this app and it worked fine years ago under Windows 98.
Trying to run it now under XP it stops receiving OnReceive callbacks after an indeterminate time - sometimes just one or two seconds, sometimes a couple of minutes or so. When the callbacks stop, other network apps on the machine also fail (i.e. Internet Explorer, Ping, Net Browser, Shared drives etc all stop working ) until I exit the app.
I have checked the network with WireShark, and the packets are still coming in as expected, just OnReceive is not called. Calls to close socket still work, and reconnecting restarts it again for a short while.
I have slowed the transmission of the packets down to just one 20byte packet per second - it still locks up.
I have called GetSockOpt(SO_ERROR..... No indication of any error.
I have even replaced CAsyncSocket with CAsyncSocketEX from elsewhere on this site and I get exactly the same results.
I am, of course, using a UI thread not a worker thread so a message pump gerts to handle the messages properly.
I have tried it on many different systems all give same problem.
Anybody got any suggestions??
|
|
|
|
|
I have managed to move this forward a little in that the application works well under Windows NT4.0.
Problem is now clearly a windows XP platform problem. With my server application running on Windows XP, and the Client on Windows NT4.0 it all works as expected.
With the client (same .exe file) running on Windows XP arrival of the ethernet packets fail to call the OnReceive function after somewhere betweeen one second and a couple of minutes. When this happens, all other Ethernet comms on the system lock up until the socket in the client is closed.
This must be an XP (tcp stack) problem?
Where do I go for help????
|
|
|
|
|
EvoWing wrote: This must be an XP (tcp stack) problem?
Extremely doubtful.
Your code probably just seemed to be working before.
With XP (and again with Vista) the system threading
performance has improved greatly and that can really expose
old problems - usually thread related.
Regardless, what are you doing in your OnReceive?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes,
its a question of looking inwards, not outwards....
I was doing nothing in the the OnReceive that I thought could create a problem but it was an unguarded CPtrList.AddTail followed a little later (in same procedure) with a CPtrList.RemoveHead. Guarding these with a CSingleLock fixed the problem...
Though I don't see why that should be necesary as only references to this list are these two in this function, and this function is only ever called as the OnReceive on this single socket in its own thread.... unless WinSock can generate multiple (overlapping) calls? Is that possible?
many thanks
Rod.
|
|
|
|
|
EvoWing wrote: and this function is only ever called as the OnReceive on this single socket in its own thread
What do you mean "its own thread"?
By default, OnReceive() is called on the UI thread.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok my code is below, my program is working okay so far but I am trying to implement the concatenate function and I have no clue how to do so. I am passing the second list to the concatenate function but I am unsure of how to create a pointer that would point to the first node of that second list object. I have a pointer created that points to the fist node of the first list but I don't know how to make one for the second list. How do I do this?
#ifndef NEWSTRING_H_INCLUDED
#define NEWSTRING_H_INCLUDED
struct Newlist
{
char data;
Newlist *next;
};
class listClass
{
public:
listClass();
~listClass();
void insert(char);
void display();
int length();
void concatenate(listClass);
void concatenate(char);
bool substring(Newlist);
private:
Newlist *head;
Newlist *current;
};
#endif // NEWSTRING_H_INCLUDED
#include <iostream>
#include "Newstring.h"
using namespace std;
listClass::listClass()
{
head = NULL;
}
listClass::~listClass()
{
if(head != NULL)
{
do
{
Newlist *nodePtr = head;
head = head->next;
delete nodePtr;
} while(head!=NULL);
}
}
void listClass::insert(char value)
{
Newlist *insert, *temp;
insert = new Newlist;
insert->data = value;
insert->next = NULL;
if(head == NULL)
{
head = insert;
current = head;
}
else
{
temp = head;
while(temp->next != NULL)
{
temp = temp->next;
}
temp->next = insert;
}
}
void listClass::display()
{
Newlist *displayPtr;
displayPtr = head;
while(displayPtr != 0)
{
cout << displayPtr->data << endl;
displayPtr = displayPtr->next;
}
}
int listClass::length()
{
Newlist *countPtr;
int count = 0;
countPtr = head;
while(countPtr != NULL)
{
count++;
countPtr = countPtr->next;
}
return count;
}
void listClass::concatenate(listClass newlist)
{
insert(newlist);
}
#include <iostream>
#include "Newstring.h"
using namespace std;
int main()
{
listClass list;
listClass newlist;
list.insert('a');
list.insert('b');
list.insert('c');
list.display();
cout << list.length() << endl;;
newlist.insert('d');
newlist.insert('e');
newlist.insert('f');
list.concatenate(newlist);
list.display();
return 0;
}</iostream></iostream>
|
|
|
|
|
Sadaiyappan wrote: I am trying to implement the concatenate function and I have no clue how to do so.
There are two ways, depending on how you want concatenate() to work. If you want to copy the data from your second list and append it to the end of the first list, simply traverse the second list, extract the value and use your insert() method to append the data to the first list.
If your intention is to link the two lists together, simply find the last *next pointer in your first list and point it to the head of the second list.
Some notes on your code: When traversing your lists, sometimes you compare against NULL and sometimes you compare against 0. Keep it consistent. It's probably better to always use NULL.
Your insert() method isn't really an insert method. It is an append method. It always adds the record to the end of the list. It makes more sense (to me, at least) that the insert() method should add the record just before your NewList *current pointer.
Also, your class maintains a *current pointer which will never point to anything other than *head (i.e. it's only set in insert() ). *current should probably be used to keep track of the current read position in your linked list so your users can actually use the list. You need a getData() method and a next() method which would allow users to read a record and move to the next record in the list. You should also include a rewind() method to set the *current pointer back to the beginning of the list.
|
|
|
|
|
I am creating application to track the usage of Function keys in the system. For that purpose i installed a system wide hook. The program also have an interface which the user can configure various settings . The hook is installed in the InitDialog of this dialog. User can also minimize the dialog to system tray. The problem is that the hook works only when the dialog is visible. If the user minimizes the app to the system tray the hook stops processing messages.
extern "C"
__declspec(dllexport) void InstallHotkeyHook()
{
hHotkeyHook = SetWindowsHookEx(WH_KEYBOARD, HotkeyMessageProc, hMod, 0);
}
The above function is called to install the hook from InitDialog.
Please help.
I am using VS6.0 and OS is WinXP SP2
Regards,
John
|
|
|
|
|
How does the HotkeyMessageProc() looks like? And how did you confirm that the call back function is not getting called when minimized...
|
|
|
|
|
Thanks for the reply.
I put a BP in the hook function..It only got breaked when i had focus on the dialog.
LRESULT CALLBACK HotkeyMessageProc(int code, WPARAM wParam, LPARAM lParam)
{
if (code > 0) return CallNextHookEx(hHotkeyHook, code, wParam, lParam);
:
:
:
}
|
|
|
|
|
When you install a global hook, the hook function is executed in each process context. That is all the process which is affected by the hook loads the hook dll and call this function in its context.
But in your your setting the break point in you application. So the break point will hit only while your applciation executes the hook procedure.
Put a mesasgebox in the hook procedure and then try...
|
|
|
|
|
emmmatty1 wrote: The hook is installed in the InitDialog of this dialog.
How will it work then? You are expecting to install a global keyboard hook - So, the hook should be installed from within a system-wide DLL, so that it could continue to process the hook messages. If it were installed from within a dialog which is not system-wide, and would work only when the dialog thread is active.
Try this:
Step 1. Create a DLL and write the hook procedure in the DLL.
#pragma data_seg(".SHARED")
static HHOOK hKeyBD=NULL;
#pragma data_seg()
#define DLLEXPORT __declspec(dllexport)__stdcall
HINSTANCE hInst;
LRESULT DLLEXPORT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (((DWORD)lParam & 0x40000000) && (HC_ACTION==nCode))
{
}
return CallNextHookEx(hKeyBD, nCode, wParam, lParam);
}
BOOL DLLEXPORT StartHook()
{
hKeyBD=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KeyboardProc, hInst, 0);
return TRUE;
}
BOOL DLLEXPORT StopHook()
{
BOOL bStatus = UnhookWindowsHookEx(hKeyBD);
return bStatus;
}
BOOL CHodllApp::InitInstance()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
hInst=AfxGetInstanceHandle();
return TRUE;
}
Step 2. Start the hook from an external module and stop it when you're done. Write back if you have troubles doing this.
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
For the life of me I can't work this out.
In the "apps" InitInstance I seed the random number generator by calling srand(time(NULL));
Then in a thread whenever I invoke rand() and print it out via cout it always has the value of 18467. Now rand() is invoked every minute or two so it's not like it's in a tight loop or anything like that. I never call srand again either. Just the once in the apps InitInstance function.
Anyone experienced this problem before? Currently using Visual Studio 2008. I even went so far as to apply SP1 to it just incase something was fixed. Such a simple thing not working is really annoying me.
Just to add if I print out rand() a few times in the apps InitInstance it works as expected. However once I call it from a UI thread it's always the same number.
modified on Monday, September 1, 2008 3:30 PM
|
|
|
|
|
jbem wrote: In the "apps" InitInstance I seed the random number generator by calling srand(time(NULL));
jbem wrote: Then in a thread whenever I invoke rand()
srand() is thread specific. You need to seed (call srand())
on every thread that will call rand().
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|