|
Hi Dear Friend,
Thanks for your attention.
I want to add simple ATL object to my MFC DLL,
|
|
|
|
|
Hi,
im using this code to copy some data from a ListCtrl
to clipboard.
void CXYZ::copyToClipBoard()
{
CString strTemp="";
POSITION pos = this->GetFirstSelectedItemPosition();
if (pos == NULL)
TRACE("No items were selected!\n");
else
{
while ((pos) && (1))
{
int nItem = this->GetNextSelectedItem(pos);
pEl=Tree.getItem(nItem);
if (pEl->sev == 1)
strTemp+="Summary";
else if (pEl->sev == 2)
strTemp+="Unknown";
}
}
if(0 != OpenClipboard())
{
// clipboard varibale and buffer to hold text
HGLOBAL clipbuffer;
char * buffer;
// empty the clipboard first
EmptyClipboard();
// Allocate enough memory
clipbuffer = GlobalAlloc(GMEM_MOVEABLE, (strTemp.GetLength()+1)*sizeof(TCHAR));
// lock the buffer for entire system
buffer = (char*)GlobalLock(clipbuffer);
// copy the text to buffer
memcpy(buffer, strTemp,strTemp.GetLength()*sizeof(TCHAR));
buffer[strTemp.GetLength()+1] = (TCHAR) 0;
// unlock the buffer for entire system
GlobalUnlock(clipbuffer);
// set the type of the clipboard data
SetClipboardData(CF_TEXT,clipbuffer);
// close the clipboard
CloseClipboard();
}
This is working fine for about 150000 items.
But when i have about 500000 items i see a strange behaviour.
The memory usage is increasing for a short time. After this it drops
back to the value before the copy attemp but the process is stuck
in the while-part of this method.
Are there any limits of a CString i`m not aware of?
Or is there an other way to copy more than 150MB to clipboard?
And as last question what way is the fastes to concatenate many strings?
Are stringstreams better or what other ways are possible?
thx
t2x
|
|
|
|
|
Using CString to cat a large number of string is very slow. Each cat can easily cause a new memory allocation which is bad. stringstream should work just fine unless the allocation system stinks. Even a vector of chars is better since it uses a doubling algorithm.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
I think you are seeing (or going to see) two problems. First, CString is not designed to do what you are trying to do with acceptable performance. Second, putting that much data on the clipboard might not be a good idea.
Using "Delayed rendering" of the clipboard data may help the clipboard performance.
Calculating how much space you will need for the completed string and/or optimizing the data transfer format, and then allocating a single buffer for the data should help performance a bit. For example, if you add up all of the characters required for all of the data, you can then do a single allocation for that size and copy the data into it. That in itself will improve performance over CString .
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
t2x wrote: Or is there an other way to copy more than 150MB to clipboard?
Just a ?, why you want to copy 150 mb data to clipboard.. it will slow down performance of PC!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I'm trying to create a fast running algorithm to calculate combinations.
Think of 3 decks of cards without without the picture cards. This would give a total of 120 cards. Now if you were to choose 14 cards from those 120, how many combinations would there be without repeats and disregarding the order. Or more to the point, how could one generate the code to show all possible combinations?
My initial idea was to create an array of all 120 cards then create 14 nested for loops, create a combination and write it to a file. Then later go through the file erasing all duplicates. But this is hardly efficient least to mention good coding. This method would also take an extremly long time. Most of the time being wasted on creating impossible combinations (more than 4 ones)
I am now tempted to create a function to randomly pick 14 of those cards, and write it to a file. But this is going to give inacurate results. There must be some sort of algorithm which can do this.
|
|
|
|
|
Yeah - I think I had that as a CS class assignment one time... I solved it rather quickly (best solution the instructor ever saw!) like this:
int main( int iArgC, char *paArgV[] )
{
int iaCards[ 120 ];
srand( time( NULL ) );
for( int iCard = 0; iCard < 120; iCard++ )
{
iaCards[ iCard ] = rand( ä.ƒóQÿÿëÏ;ðt’f÷Æ.üu®‹ÎÁ +++ NO CARRIER
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
That's just cruel
Seriously, when was the last time you saw a "NO CARRIER" error halfway through a transmission?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
waldermort wrote: This would give a total of 120 cards. Now if you were to choose 14 cards from those 120, how many combinations would there be without repeats and disregarding the order.
120! 6.68950E+198
------------ = ------------ = 6.69414E+17
14!(120-14)! 9.99308E+180
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
Show-off! I had to write all that code to get the answer...!
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
whats the C function from C standart libs to convert from wchar_t string to char string.
Is it just simle to do it this way:
for(i=0; i
|
|
|
|
|
and from char to wchar_t string also?
9ine
|
|
|
|
|
wctomb or mbtowc
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
To my knowledge, there are no "standard C" ways to do that, but there are two functions in the Win32 API that you will want to look at: MultiByteToWideChar(...) and WideCharToMultiByte(...) .
Peace!
-- modified at 9:14 Thursday 16th February, 2006
Whoops - guess I was mistaken given what Alok posted... My knowledge has expanded!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
James R. Twine wrote: Whoops - guess I was mistaken given what Alok posted... My knowledge has expanded!
You were not mistaken. The functions that Alok posted are CRT wrappers of the functions you posted. There are also the ATL conversion macros ( A2W, W2A, T2A, T2W, ect.) which also end up calling MultiByteToWideChar or WideCharToMultiByte.
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks! Actually, I figured as much by the names of the functions (mbtowc - MultiByteToWideChar ), but since the function is declared in <stdlib.h> , and you need to link in the C Runtime Library to get at it, I thought it qualified as "standard" (even if it is Win32/Win64 "standard") .
Thanks!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
I want to uniquely identify a given system based on a set of parameters like ethernet address etc. Could some please provide me with a list of uniquely identifiable params Also I would like to collect the same details for Windows OS.
Also I see that some of these params need either a COM interface to query for or one have to code in assembly to retrieve them. Could someone provide with Windows SDK method of querying these params?
|
|
|
|
|
I do not think that there is a perfect way to do this. Many things that one would normally think of, the the MAC address, can be changed (at least, some NIC cards allow you to change the MAC address).
And I think that other things, like a CPU or a drive serial number, can be spoofed with the right (driver level) software.
You might be better off generating and managing IDs from a central location and assigning them to target systems yourself.
Whatever you do, please do not use this for something like software activation - it is a serious pain in the ass to disable something in Device Manager and make Windows Activation lose its mind...!
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
The second line aliases the keyword new to DEBUG_NEW, which is itself a macro defined in the Microsoft-specific header afx.h. DEBUG_NEW references THIS_FILE and __LINE__, thereby capturing the faux new's source context for possible tracing and debugging.
----
Can any one pls. explain the purpose of undef in the code above.
This code is almost present in almost in every file, in debug version after debug new is defined, THIS_FILE is used in debugging only then undef is un-defining it then what is the purpose of THIS_FILE.
Rgds,
Arun.
|
|
|
|
|
#undef simply says to the preprocessor that the THIS_FILE macro is not defined anymore after this point of reading...
the same question was asked yesterday... see this[^]
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
-- modified at 5:13 Thursday 16th February, 2006
|
|
|
|
|
Yes, I have seen that but couldn't understand that.
Infact this code or the pre-processor directive is excuted in the beginning of the file, if we undef THIS_FILE and defining it again what might have been the value before and now for debugging purposes it's changed to be __FILE__.
can you pls. elaborate what is the value before undefining it.
Rgds,
Arun.
|
|
|
|
|
arunperi wrote: what is the value before undefining it
why do you need to know that ?
i don't know !!
maybe defined without value...
#define THIS_FILE
look in your headers to find the correct definition...
even MSDN[^] don't say much...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]
-- modified at 5:36 Thursday 16th February, 2006
|
|
|
|
|
Thank you,
just trying to figure out what could be the purpose of that statement
Rgds,
Arun.
|
|
|
|
|
it's there to prevent the compiler from complaining about multiply-defined macros, in case something else in the #include chain has defined something with that same name.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
hy everybody,
i really have a strange problem, and i hope that this very nice forum can help me out another time.
So what i have is a very simple com dll, if followed this article to build it: COM-DLL
my prroblem is, when e have a function like this:
[id(5), helpstring("method test2")] HRESULT test2([out,retval] BSTR* str);
i want to return more Parameters with the [out,retval], not only a BSTR* maybe a sequence or an array would be nice! In my Project i have to return 20 Strings to the Client who is using this dll, how does this work?
maybe something like this:
[id(5), helpstring("method test2")] HRESULT test2([out,retval] BSTR* str[20]);
I dont know or passing a sequence or an struct as a return Parameter?
Or what about this VARIANT* Types how does this work?
[id(5), helpstring("method test2")] HRESULT test2([out,retval] VARIANT* );
Please could someone explain it to me, i really need this asap...
Really, thank you in advance,
greetz
Balu
|
|
|
|