|
That will break if the contents of str are modified. GetBuffer() is the right way to get a non-const pointer to the string.
--Mike--
http://home.inreach.com/mdunn/
Ford: How would you react if I said that I'm not from Guildford after all, but from a small planet somewhere in the vicinity of Betelguese?
Arthur: I don't know. Why, do you think it's the sort of thing you're likely to say?
|
|
|
|
|
You can create a CString from a char*, and to go back do this
CString s;
s.GetBuffer(s.GetLength()+1);
s.ReleaseBuffer();
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Also, if you just need to pass a const char* to a CRT/WinAPI function, you can use
CString s = "a string";
CallMyCharFunction((LPCTSTR)s);
But if you really need a char* , use the methods above.
CodeGuy
The WTL newsgroup: 910 members and growing ... http://groups.yahoo.com/group/wtl
|
|
|
|
|
strcpy(szstr, str.GetBuffer()); //where str is a CString and szstr is a char*
Cheers!!!
Carlos Antollini.
|
|
|
|
|
I face some problem regarding the deadlock issues.
I am implementing a dining philosopher simulator and try to compare various algorithms. Some algorithm will cause deadlock as I expected.
However, is there any ways that I can explicitly release the thread from the deadlock (ie: like click on a "release philosopher from deadlock" button) after I am happy enough to see what deadlick look like.
One of my solution is using
WaitForSingleObject(chopstick_monitor, SOME_LONG_TIME);
instead of
WaitForSingleObject(chopstick_monitor, INFINITE);
However, is there any better way so that the philosopher will always remains at the deadlock state unless I command them to recover from deadlock.
thank you. if possible, pls e-mail the solution to yccheok@yahoo.com
regards
yccheok
|
|
|
|
|
Have your philosophers wait for two events instead of one, and use the second to signal deadlock recovering:
HANDLE handles[2]={chopstick_monitor,deadlock_recover};
switch(WaitForMultipleObjects(2,handles,FALSE,INFINITE)){
case WAIT_OBJECT_0:
...
break;
case WAIT_OBJECT_0+1:
...
break;
...
} Better yet, have one deadlock recovering event for each philosopher so that you can control them individually.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
The question and topic I want to ask is...
How can I interface my VC++ application with a VB application so that I can pass data between the two?
I have looked at some concepts like DLLs, COM, COM+, DCOM, ATL, ... but all text that I skimmed at the local bookstore have left me puzzled and said a lot without saying anything.
Specifically, I have a list class in my VC++ application that contains a linked list of data elements. I want to be able to pass this to my VB application so that I can do work on this data in VB (display, manipulate, "rewrite the list"). While in VB application, I will probably work with the data in an array structure. Then, send a modified version of the data back to my VC++ application so that it can work with the data as if it were in its original state (linked list with new links.)
Could someone please point me to what I should read/study or the topic under which this interfacing falls under? Thanks for the answers and guidence in advance.
Johnny
|
|
|
|
|
I've worked a lot with VB - VC coupling, and I found two good ways to interoperate:
1) Make a COM bridge for every C++ class you want to use from VB. You can do it pretty nice with ATL, but of course, you can use "bare bone" COM, if you wish.
2) For every C++ class, make a corresponding VB class, and make a DLL that will "glue" them. In every VB class you will have a long private member that will hold the memory address of the corresponding C++ class.
If I were you, I would take the first route, although the second one also works fine.
I vote pro drink
|
|
|
|
|
I don't know anything about VB, and I don't know what versions of Windows you need to support.
But, I have made a lot of communication between programs using Named Pipes.
The "server" (listening) application needs Windows NT/2000/XP, so I don't know if you can use that...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I can trade help if you like..
I can solve this for you if you can solve my question
email me if you are interested
|
|
|
|
|
Hi fellas!
I have a technical questiom:
Does Windows NT 4 support SSE instructions? and if it originally does not from which SoftWare pack it supports SSE instructions.
Thanks in Advance
Damon
|
|
|
|
|
I'm having a very bizarre problem with a Visual C++ program I'm working on. The program seems to crash with an access violation when one of 3 certain string variables are accessed. I know it's 3 because for some reason switching the order of the variable declaration seems to switch the crash to one of the other 2 variables. I have no idea why this is happening or what do do about it. It just started all of the sudden in a part of the code I hadn't even changed. It only happens in Debug mode, only on my machine, and only with this project(I've never seen this before in any other project). I've since upgraded my RAM by 128MBs and reinstalled Visual C++ 6. This didn't fix the problem. Has anyone else ever encountered this before? How did you fix it?
Why not throw away a dime,
I throw away ten pennies all the time...
|
|
|
|
|
Hi Kevin,
The program seems to crash with an access violation when one of 3 certain string
variables are accessed. I know it's 3 because for some reason switching the order of
the variable declaration seems to switch the crash to one of the other 2 variables
How about posting some code.
It is Illogical to define an inventor by his invention
|
|
|
|
|
That just screams stack corruption. Are all your stack arrays large enough? Are you passing in a variable by pointer when it shouldn't be (type checking usually catches this unless you have to cast to (void **) with such things as QueryInterface.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Do you have multithreading client/server code that you can give to me?
I need example code! because I think its to big for you to explain it here and now!
/*
BETA
*/
|
|
|
|
|
see
http://www.codeproject.com/internet/chessserver.asp
It is Illogical to define an inventor by his invention
|
|
|
|
|
Hello,
I am trying to establish a connection and I think I am missing something very basic. I get an "Invalid Pointer" error when the Open() is called. I am importing msado15.dll in StdAfx.h which is included in the file that contains the code below.
My code:
_ConnectionPtr pConn;
HRESULT hr;
try{
hr = pConn.CreateInstance(__uuidof(Connection));
_bstr_t bstrDSN = "DSN=test_db;UID=gstewart;PWD=gstewart";
pConn->Open(bstrDSN,"","", -1);
}
catch (_com_error e){
MessageBox(e.ErrorMessage());
}
|
|
|
|
|
try catch (_com_error &e)
|
|
|
|
|
The catch block shouldn't be executing in the first place. For some reason my connection pointer isn't valid after
hr = pConn.CreateInstance(__uuidof(Connection));
is executed. Any ideas what I'm missing? I think I'm missing a header file or something. It comiles just fine though....????
|
|
|
|
|
This is the code I use to create an ADO connection, the only difference I can see is that I pass cast my empty strings to _bstr_t first.
Are you getting a compile error or a runtime error
_ConnectionPtr m_pConnection
HRESULT CAdoConnection::Connect(std::string sConnectionStr)
{
HRESULT hr = S_OK;
try
{
hr = m_pConnection.CreateInstance(__uuidof(Connection));
if(hr == S_OK)
{
hr = m_pConnection->Open(_bstr_t(sConnectionStr.data()), _bstr_t(""), _bstr_t(""), adConnectUnspecified);
}
}
catch (_com_error &e)
{
}
return hr;
}
Michael
|
|
|
|
|
Michael,
I tried the casting and also added the adConnectUnspecified argument. My error occurs at runtime on the Open(...).
Thanks,
Glen
|
|
|
|
|
What error number does the try and catch get for the open?
Michael
|
|
|
|
|
After hr = pConn.CreateInstance(__uuidof(Connection));
the value of hr is -2147221008. I can't seem to get anything more from the _com_error object that is thrown except that the errormessage says "Invalid Pointer". I wonder if there could be something wrong with my compile options?
|
|
|
|
|
Did you use the CoInitialize()?
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Hi,
I have an SDI application that uses a CFormView. I have a third party graphics ActiveX control on the CFormView. I need to be able to scroll the CFormView because I want to make the ActiveX control bigger than the viewable area. Can someone help me with the steps to be able to scroll a CFormView?
Thanks for any help you can provide,
Craig
|
|
|
|