|
I have the following code that I'm having problems understanding.
WHO_RU_API int GetNetUserLoginId(char* pBuffer, int nBufferSize)
{
int nCharCount = 0;
WKSTA_USER_INFO_1 UserInfo;
if ( NERR_Success == NetWkstaUserGetInfo(NULL, 1, (LPBYTE*)&UserInfo) )
{
int nCount = WideCharToMultiByte(CP_ACP, NULL, (LPCWSTR)UserInfo.wkui1_username, -1, NULL, NULL, NULL, NULL);
if ( nCount > 0 )
{
char Buffer[32];
int nCountAgain = WideCharToMultiByte(CP_ACP, NULL, (LPCWSTR)UserInfo.wkui1_username, -1, Buffer, nCount, NULL, NULL);
if ( nCountAgain > 0 )
{
nCharCount = strlen(strncpy(pBuffer, Buffer, min(nBufferSize, nCountAgain)));
}
}
}
return ( nCharCount );
}
I have this function inside a DLL and I'm calling it from a console program. Eveuntually it will be a windows app calling it. The part I don't understand, is that following the second call to the WideCharToMultiByte() function, my 'Buffer' contains a string of 8 illogical characters and the 8 characters of my Lan Id. I know I'm missing something important here, but I'm too lost to see the forest for the trees at the moment . Any help would be appreciated. Thanks.
Chris
|
|
|
|
|
try to type as followed...
TCHAR myBuf[256];
wcstombs( myBuf, UserInfo.wkui1_username , 255 );
...
by
by Peng_you
|
|
|
|
|
Does anybody here have any experience utilizing DirectX/DirectShow in order to create capture devices/encoding devices? If so, could you please let me know, I have some questions that I cannot find the answer to and am hoping someone here can help. Thanks in advance.
Roger Printy
Software Engineer
TeraNex
Orlando, FL
|
|
|
|
|
Hi
Can some one tell me, how I can get the HTML-Code of a page, when i use a CHtmlView to show this page.
thank's
|
|
|
|
|
First, use CHtmlView::GetHtmlDocument to get IDispatch interface. Then call QueryInterface to get IHtmlDocument2 interface pointer. Finally, use IHtmlDocument2::toString method.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
You can get an idea here
http://www.codeproject.com/useritems/chtmlview_search.asp
Carlos Antollini.
|
|
|
|
|
Hello, the codegurus around the world.;)
In order to get the source code of html on CHtmlView, you can use GetHtmlDocument and IPersistFile.
Since we can get IDispatch from GetHtmlDocument, we use QueryInterface passing IPersistFile's IID.
After this, we can use Save function of IPersistFile to save the source code at the local drive and check it NotePad executed
by ShellExecute.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hello,
I just converted an article at the "other" site (http://www.codeguru.com/listview/VirtualListControl.html) from CArray to std:vector. The performance increased 5 times! The only section that I didn't like was the column sorting method. It uses the qsort() function to sort the columns. It seems there would be a more elegant (STL) method of doing this. There is a class defined for a row of data similar to this (shortened for clarity):
class CRowData {
CString col1;
int col2;
}
The qsort function calls the appropriate comparison function to sort on the desired member. It seems like there should be a way to do this using the STL. I would like to expand this example to include sorting on more than two columns as well.
Any ideas?
Thanks,
Derek
Doble Engineering
|
|
|
|
|
Are you also getting 500% performance improvement in Release build?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Actually it's not as high as I thought. I was comparing debug build to debug build. Using the metrics (GetTickCount) the original author already had in the code (approximate tick values):
CArray:
Debug: 2000
Release: 250
STL:
Debug: 600
Release: 90
List Control InsertItem():
Debug: 15000
Release: 12000
STL Improvement:
Debug: ~ 3.3x
Release: ~ 3.3x
These are after a few runs, but there was definitely an improvement. Either was an improvement over the InsertItem method! I know all of these results are completely subjective (compiler settings, computer speed, etc.), but try it yourself to see the difference!
Also, any ideas on converting the sorting to STL?
Thanks,
Derek
DP
|
|
|
|
|
The speed increase you're experiencing is caused by smaller number of memory reallocations when you add items to your array/vector. CArray grows by constant number of elements, while std::vector (version shipped with VC++) doubles its buffer size when it needs to grow.
Access time to array/vector elements should be identical in Release build - it's *very* simple container; compiler should generate almost identical code. In Debug build, the story is different: STL implementation that ships with VC++ DOES NOT check indices in vector::operator[]. If you're a former CArray user, this may come as total suprise - you can v.resize(10) your vector and use v[100] without assert. In other words, in Debug CArray will be slower, but safer.
The freely available STLPort (www.stlport.org) performs index overflow checking in debug build - I strongly recommend this version of STL.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
take a look at std::sort
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
I thought about this, but I'm not sure how to approach it. If I have a class:
class CRowData {
CString col1;
int col2;
}
and I defined a vector as:
std::vector<crowdata> vecRowData;
and I want to use std::sort, then I have to override the operator< and operator==. This means I can only sort on one variable in the operator< method. How can I specify which variable to sort on?
DP
|
|
|
|
|
Use std::sort that takes three arguments. The last one is a predicate - you can pass one predicate when you need to sort by col1, another for col2.
Since it seems that performance is important to you, note that while qsort just shuffles bits around during sorting, std::sort will perform assignments. Depending on members of your struct, it may have impact on perf. Post some results when you're done with this
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
there are many flavors of std::sort. some of them take what's called a 'predicate'. this is essentially a custom comparison function. so, you can sort on anything you like.
bool predicateFunction(const CMyStruct& a, const CMyStruct& b)
{
return (a is somehow less than b);
}
vector <CMyStruct> vec;
...
std::sort(vec.begin(), vec.end(), predicateFunction);
so, you just use different predicate functions when you want to sort in different ways (differnet members, direction, etc.)
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thank you for the code snippet! It was just what I needed! I created two sort functions:
bool sortCol1(const CLabelItem& a, const CLabelItem& b)
{
return (a.m_strText < b.m_strText); // CString
}
bool sortCol2(const CLabelItem& a, const CLabelItem& b)
{
return (a.m_Addr < b.m_Addr); // DWORD
}
and did the sort comparision only on the STL modified code. Here are the results (in ticks) for 50000 rows:
Debug Release
qsort:
CString 55000 22000
DWORD 220 50
STL sort:
CString 1221 420
DWORD 750 220
Summary ( IMHO )
Use STL for code simplicity and maintenance and use STL sort unless the extra 150 ticks for DWORDs are important!
My thanks to all for all the help!
Derek
|
|
|
|
|
So the qsort is *much* slower for CString sorting? It's rather counter-intuitive, but still possible. Could you post your function that qsort calls back?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
Well,... I "screwed up" again I guess I was comparing apples and oranges. The qsort method used the strcmp (C-runtime) function to compare strings. I used CString's operator> method to compare. Both give the same answer, but the CString was much faster. I didn't bother replacing the STL sort code with the strcmp code, because I'm sure it would be slower than qsort's.
Sorry for the misleading results!
Derek
|
|
|
|
|
Hello,
I just converted an article at the "other" site (http://www.codeguru.com/listview/VirtualListControl.html) from CArray to std:vector. The performance increased 5 times! The only section that I didn't like was the column sorting method. It uses the qsort() function to sort the columns. It seems there would be a more elegant (STL) method of doing this. There is a class defined for a row of data similar to this (shortened for clarity):
class CRowData {
CString col1;
int col2;
}
The qsort function calls the appropriate comparison function to sort on the desired member. It seems like there should be a way to do this using the STL. I would like to expand this example to include sorting on more than two columns as well.
Any ideas?
Thanks,
Derek
Doble Engineering
|
|
|
|
|
Where is the flag that I can set in MS Visual C++ that will allow me to have an instance of MS Visual C++ open, then double click a .dsw in Windows Explorer and have that workspace open in another instance of MS Visual C++? I know I have something set somewhere that allows this, I just cannot remember. Any help?
Roger Printy
Software Engineer
TeraNex
Orlando, FL
|
|
|
|
|
Is there a way using the C++ automation to find out the location of the project/file in the SourceSafe?
The only solution that I see for now is to find out the path of the project and than to parse the .dsp or .dsw file to find out the path of the project in the SourceSafe.
I would like to do this without parsing the .dsp or .dsw file...
Thanks.
Rasstislav
|
|
|
|
|
when trying to click on a listbox created in runtime over an edit control in a formview, the existing edit control under the listbox control gets a focus. so i can't select an item in a listbox. somebody help me...
by peng-you.
|
|
|
|
|
hmmmm
try either setting the z-order of the listbox to be in front of the edit control ... maybe destry the edit control ... disable it ... or use a combobox that allows the user to type stuff into the list control portfion and add some custom behaviour to stop the item being added to the list
---
"every year we invent better idiot proof systems and every year they invent better idiots"
|
|
|
|
|
How can I make my CFileDialog to accept directories and return the full path name of the directory. Something like what I get when I select File / New option in the MSDEV IDE and click on the "..." button next to Location Edit box ??
Sudha Shriram
|
|
|
|
|
You don't need CFileDialog for that. Use SHBrowseForFolder instead.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|