|
Is it S_OK to use W2A to convert from a BSTR to a const char * ?
Means, can I do this?
const char * p = W2A(bstrBlah);
Nish
p.s. I am doing this now and without any problem. But I just wanna know if it is safe!
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
|
Yes, a BSTR holds Unicode characters, so W2A() is perfectly fine.
<nitpick>
Since you're assigning to a const char*, use W2CA() instead.
</nitpick>
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
Michael Dunn wrote:
use W2CA() instead
Thanks Mike
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Dear All,
APPLICATION:
To run two processes simultaneously
Brief Description of Project
64 i/os are interfaced using 8 i/o modules that communicate with PC via RS232/RS485 converter. Modules are microcontroller based which give input data to PC coming from the machine and pass on the output data generated by the PC, back to the machine.
The code is written in VC++ and used multithreading for parallel process. The operation needs some TIMERS for wait process.
Following are the queries:
1 The process demands TIMERS are to be continuously monitored for elapsed time and saved in an .ini file format when thread is in running state. Can anyone suggest the right method of doing so?
2 Only two threads are being used. Here, we are using ‘SwitchToThread()’ function to switch the system resources between two processes. Is this the right method ?
Following is the brief code we have used:
CreateThread() T1 // in SDK DLL
{
Function1(); // To read the .ini file for process 1
{
SwitchToThread();
}
}
CreateThread() T2 // in SDK DLL
{
Function2(); // To read .ini file for process 2
{
SwitchToThread();
}
}
Please spare some time and give me your valuable suggestions.
|
|
|
|
|
I would use WaitforMultipleEvents -Stuff in addition to some timing events.
|
|
|
|
|
Hi
How can i transfer some binary data from one machine to
another. The two machines have a Modem (USB) and i want
to develop under VC++.
Please help
Sameer
|
|
|
|
|
If you can't use a floppy disk for some reason, set one modem to receive and use the other to send. You'll need some kind of communications software as well. You could also email the file from one machine to the other if both have access to email accounts. Without more info about your hardware, OS, size of binary data, etc., it is difficult to give a complete answer.
|
|
|
|
|
I need to sort some data in a flex grid and seem to be having some trouble. I have the Row/Column fixed data finished, but when I try placing data into the other fields it becomes all eratic as some data is left out and other data is repeated. If anyone would take a look at my code and give me an idea of what I am doing wrong I'd REALLY appreciate it. The work I am doing requires me to use the FlexGrid.
My code is listed below.
Thanks in advance,
Garry
void CFGridDlg::LoadData()
{
//Get the grid row count
int liCount;
//Initialize the random number generator
srand((unsigned)time(NULL));
//Create and array
for (liCount = m_ctlFGrid.GetFixedRows();
liCount < m_ctlFGrid.GetRows(); liCount++)
{
//Generate the first Column (Jan) values
//m_ctlFGrid.SetTextArray(GenID(liCount, 0), StringValue(1));
//Generate the second column (Jan) values
m_ctlFGrid.SetTextArray(GenID(liCount, 1), StringValue(1));
//Generate the third column (Feb) values
m_ctlFGrid.SetTextArray(GenID(liCount, 2), StringValue(1));
//Generate the fourth column (Mar) values
m_ctlFGrid.SetTextArray(GenID(liCount, 3), StringValue(1));
//Generate the fifth column (Apr) values
m_ctlFGrid.SetTextArray(GenID(liCount, 4), StringValue(1));
//Generate the sixth column (May) values
m_ctlFGrid.SetTextArray(GenID(liCount, 5), StringValue(1));
//Generate the seventh colummn (Jun) values
m_ctlFGrid.SetTextArray(GenID(liCount, 6), StringValue(1));
DoSort();
}
}
int CFGridDlg::GenID(int m_iRow, int m_iCol)
{
//Get number of columns
int liCols = m_ctlFGrid.GetCols();
//Generate ID's. based on number of Rows, the current row, and the current column
return (m_iCol + liCols * m_iRow);
}
CString CFGridDlg::StringValue(int m_iColumn)
{
//The return Str.
CString reStr;
//Random Value ID
int raCase;
//Set the selection to column 1
//m_ctlFGrid.SetCol(1);
{
//Generate random val.
raCase = (rand() % 5);
//What val was generated?
switch (raCase)
{
case 0: //Rent
reStr = "$650.00";
break;
case 1: //Insurance
reStr = "$259.00";
break;
case 2: //Utilities
reStr = "$130.00";
break;
case 3: //Car payment
reStr = "$220.00";
break;
case 4: //Loans
reStr = "$60.00";
break;
default: //Credit cards
reStr = "$30.00";
break;
}
}
return reStr;
}
void CFGridDlg::DoSort()
{
//Set the current column to column 1
m_ctlFGrid.SetCol(1);
//Set the selection to all columns
m_ctlFGrid.SetColSel((m_ctlFGrid.GetCols() - 1));
//Ascending sort
m_ctlFGrid.SetSort(0);
}
|
|
|
|
|
Hi,
I wonder how the internal CAsyncSocket message loop works?
Basically I understand that a asychronous network class regular checks sockets for changes and calls a corresponding notification handler. This is done in CAsyncSocket::DoCallBack() (file Sockcore.cpp). The first attached socket handle creates a CWnd (with window name "Socket Notification Sink"). With some message spying I found out WM_SOCKET_NOTIFY is regular send to this internal window and calls CAsyncSocket::DoCallBack() .
Unfortunately, the message routing isn't easy to understand (mixture of CAsyncSocket and CSocket). My questions:
How is the first WM_SOCKET_NOTIFY send?
Who keeps he notification loop alive (who and how often sends further WM_SOCKET_NOTIFY)?
Thx for help, Moak
|
|
|
|
|
How is the first WM_SOCKET_NOTIFY send?
By Winsock, i.e. by the system itself. Notification thru Windows messages is one of the mechanisms available (other is thru events.)
Who keeps he notification loop alive (who and how often sends further WM_SOCKET_NOTIFY)?
It is the message loop of your own app. These messages are handled just like say regular GUI messages. As for the frequency and sequence of notifications, have a look at WSAASyncSelect for further info.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
thx for your explanation!
I took a look into MSDN and it sounds logical now.
|
|
|
|
|
GDay All,
I was hoping someone out there would be able to inform me
how to set overlay images using a CListCtrl and LVITEM or point
me in the direction of an existing tutorial etc.
//So far this is a summary of what i have
m_OverlayImageList.Create( 16,16,TRUE,8,1);
HICON hIcon;
hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON));
m_OverlayImageList.Add( hIcon );
m_ListSelected.SetImageList( &m_OverlayImageList, LVSIL_STATE );
//then after ive inserted my lvItem i try
LVITEM lvItem;
lvItem.mask = LVIF_STATE;
lvItem.state = LVIS_OVERLAYMASK;
lvItem.iImage = 1;
m_ListSelected.SetItem( &lvItem );
... ofcourse this doesnt work else i wouldnt be asking for help,
Any help will be much appreciated.
|
|
|
|
|
You're missing a few steps. Overlay images have to be specified as such in the image list before they can be used. Say you've got two icons in the image list, and you want to use the second one as the overlay:
m_ImageList.SetOverlayImage(1,1);
(image indexes are 0-based, so index 1 = the second image; overlay indexes are 1-based, so index 1 = the first overlay image)
Now you have an overlay defined, and you can set the icon to be drawn with the overlay:
lvItem.mask = LVIF_STATE|LVIF_IMAGE;
lvItem.iImage = 0;
lvItem.stateMask = LVIS_OVERLAYMASK;
lvItem.state = INDEXTOOVERLAYMASK(1);
That should do it!
--------
You can change the extention so it reads ASP even though it is PHP which is kind of cool. - Martin Marvinski --Shog9 --
|
|
|
|
|
Hi,
I want to develop a small application that receives calls and then according to some data received, does some processing and sends some data to the client.
Please provide some links
Sameer
|
|
|
|
|
Which OS? If just 2000 then you'll be better off using TAPI3, if you want to run on the dreaded 9x machines then you'll be stuck with TAPI2.
The platform SDK has plenty of decent TAPI examples, but there are very few decent TAPI sites on the web.
http://www.sellsbrothers.com/writing/telprog/ should be a starting point as it has a few links that will be useful.
The Microsoft TAPI newsgroups are probably your best bet for getting questions answered. My TAPI experience is more with real telephone systems rather than data transfer.
Michael
|
|
|
|
|
Hello Everybody!
I need some help in understanding Message Queues when creating an UI thread.
I have created a thread that does a lengthy action delivered using SendMessage. Whenever I need the thread to complete this action, a PostThreadMessage is post this request to the thread's message queue.
This creates a bottleneck at the queue because more messages are being pumped into the queue then they can be processed!
Is there a limit to how many messages that a message queue can hold?
Any help with this problem is greatly appreciated!
|
|
|
|
|
Hi,
Actually speaking there is no declared limit for the
number of messages. But if the same messages are being
sent continuously - you could test by using
PeekMessage and remove the trailing messages
for each message(the specific kind) you are processing.
|
|
|
|
|
Thank you Prem for your suggestion.
The same message is being sent continously and each message is important to be processed. However, I don't quite understand what you mean by the trailing messages. Could you elaborate on that?
|
|
|
|
|
There is no practical limit, that I know of. Are you losing messages? How far behind is the worker thread that receives the messages? If the thread spends a significant amount of time waiting, you have extra cycles available. You could try using more that one thread to relieve the bottle neck.
|
|
|
|
|
Thank you for your suggestion, Bill. I will try to look into that.
|
|
|
|
|
I write an Application which uses another DLLs.
In the DLL_DS, it contain a DataService class, which with functions to get something from the database, and return the list of something, say:
<br />
CSimpleKeyList *CRebDataService::GetSimpleKeyList()<br />
In the DLL_TY, it holds the basic definition of some class, say:
<br />
class CHRISTINE_EXPORT CSimpleKeyDetail <br />
{<br />
public:<br />
CSimpleKeyDetail();<br />
virtual ~CSimpleKeyDetail();<br />
<br />
CString GetKeyID() const;<br />
long GetKey() const;<br />
CString GetKeyName() const;<br />
<br />
void SetKeyID(const CString& keyid);<br />
void SetKey(const long key);<br />
void SetKeyName(const CString& keyname);<br />
<br />
protected:<br />
<br />
CString m_KeyID;<br />
long m_Key;<br />
CString m_KeyName;<br />
};<br />
One of header file of DLL_TY defines the template of CDualMapListType (which is just a std::map), and
<br />
typedef CDualMapListType<CSimpleKeyDetail> CSimpleKeyList;<br />
The Application includes the header file, and is getting a CSimpleKeyList *plist from DLL_DS, but when loop through the list, an access violation occurred.
<br />
for (itr=plist->begin();itr!=plist->end();itr++)<br />
{<br />
CSimpleKeyDetail *pKeyDetail = itr->second;<br />
keyid = pKeyDetail->GetKeyID();
<br />
... ... ...<br />
}<br />
Now, I am wondering if CString can be passed between the DLL and the App, or even I can't pass the pointer to a std::map from DLL to the app, where memory is allocated in the DLL, and deletion is in the Application.
Can anyone showe me the hint ??
Thanks very much
|
|
|
|
|
This gets asked every so often. You'll be safe if all the components that make up the program (main app and DLLs) use the same DLL version of the C run-time library (i.e. no static linking of the run-time). Try it, it should work.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I've checked all the DLL's and the App are using Debug Multithreaded DLL in all Project Settings.
The strange is, in the map I contain two elements, I can get the first one with itr->second. However, for the second one, I get the CSimpleKeyDetail * with itr->second, it returned an address of cdcdcdcd. It makes me confused.
By the way, I'm using VS6 SP5 in Windows XP box.
|
|
|
|
|
Will it be any chance that the standard library (std::map) is using *another* method to allocate memory, so the memory is invalid after passing through DLL - App boundary ?
|
|
|
|