|
Hi all,
i have two char buffers char a[1000],char a1[100].
i want to copy 100 value from a to a1, but everytime the index where we should start copying is different i.e. sometime it should start copying from a[100], other time from a[268].
For Copying from one buffer to another we can use function memcpy_s but it starts copying from zero.
Is there any alternate for this.
Thanks in advance
|
|
|
|
|
Just continue using memcpy_s starting from the right address, e.g.:
errno_t result;
result = memcpy_s(a1, sizeof(a1), &a[268], sizeof(a1));
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
You are welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Im using CCriticalSection object as a parameter to CSingleLock.
When i try to create the lock object i get the:"Access violation reading location".
Why could it be?
Thnks
|
|
|
|
|
can you show us your code?
|
|
|
|
|
Hello,
I think i know what my mistake was.
I used the same CCriticalSection as a parameter to different CSingleLock objects to synchronize different resources.
I have four threads two of them use one mutual queue and the other two use other queue so i used the same CCriticalSection object as a parameter to two CSingleLocks.
Now i defined seperate lock for each queue and it works fine.
Thanks any way
|
|
|
|
|
Hi! I would like to put a file in the clipboard like when you click on a file and you copy, how can I do that?
I tried in c++ with setclipboarddata() with filename (49158) and filenameW (49159) format but doesn't work, inside the clipboard there are some other formats that I don't know. The complete list of the format is:
49161, 49268, 15, 49349, 49340, 49158, 49159, 49171.
|
|
|
|
|
I've no idea what all these numbers are supposed to mean, but I would suggest you copy the path of the file into the clipboard rather than its content. Perhaps if you show the actual code you are trying to use, someone can help you.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Ok, thank you, actually to put in the clipboard the path is what I want to do, not the content of the file, in other word I want to do the same thing that you do on windows when you select a file and click on copy.
The code:
(filename format 49158)
char path[]="C:\\file.txt";
int size=strlen(path)+1;
hglbDato = GlobalAlloc(GMEM_MOVEABLE,size);
PVOID pv = (PVOID) GlobalLock(hglbDato);
memcpy(pv,path,size);
GlobalUnlock(hglbDato);
SetClipboardData(49158,hglbDato);
and I do the same for format filenameW (49159) but instead to use a char array I use a wchar array and wcslen() instead of strlen(). Obviously the file.txt exists.
|
|
|
|
|
What is this number 49158 about and where does it come from? The valid values for this parameter are as described here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
From the file manager I select a file and I copy it in the clipboard than I debug this code and that numbers are the values in the variable format. This code open the clipboard and load every clipboard's format in a list.
struct formato{
UINT tipo;
int dim;
char * dato;
};
listFormati.erase(listFormati.begin(),listFormati.end());
if(!OpenClipboard(hWnd))
MessageBox(hWnd,_T("OpenClipboard"),_T("Error"),MB_OK);
unsigned int countFormat= CountClipboardFormats();
UINT format=0;
for(int i=0;i<countFormat;i++){
format=EnumClipboardFormats(format);
HGLOBAL hglb;
hglb = GetClipboardData(format);
int szhglb;
szhglb = GlobalSize(hglb);
struct formato *f = (struct formato *)malloc(sizeof(formato));
if(hglb != NULL)
{
PVOID pvoid = (PVOID) GlobalLock(hglb);
char *ft = (char *)malloc(szhglb);
memcpy(ft,pvoid,szhglb);
f->dim=szhglb;
f->tipo=format;
f->dato=ft;
listFormati.push_back(f);
GlobalUnlock(hglb);
}
else
{
MessageBox(hWnd,_T("hglb==NULL"),_T("Error"),MB_OK);
}
}
CloseClipboard();
|
|
|
|
|
Those values are used by the FileManager as Registered formats so are not necessarily available for user programs. You should use the standard formats in your own program. unless you have details of the actual content stored by such a format.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
With debug I discover that 49158 is the char path of the file while 49159 wchar path. I tried also save all the formats in my list than to erase the clipboard and reload the formats that I stored in the list and I discover that the formats 49158 and 49159 are not necessary to paste the file (it also works without them). My problem is to understand what format to put in the clipboard to do the same work that the file manager does. Other interesting thing I'm trying it on a virtual machine and seems that when you restart the IDE or maybe the os, there are same format that changes their number idetification of the format while others (49158, 49159 ,etc) have the same number.
|
|
|
|
|
Just use the standard CF_ values as defined in the link I gave you earlier.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Hi, I am Asking WHY?
I have a big problem when i want use this command from API:
<big>SendMessage( hFocusWin, WM_COPY, 0, 0 );</big>
its don't work correct any where.
i define a hot key (Ctrl +q) that work correctly.
but it sometimes return highlighted (selected) text and some times it doesn't work.
for example it return correct selected text in Firefox browser and doesn't work correctly in Google chrome .
why ?
|
|
|
|
|
As the documentation[^] states:
Quote: An application sends the WM_COPY message to an edit control or combo box to copy the current selection to the clipboard in CF_TEXT format.
So if your target uses a standard edit control (or combo) or something derived from it, WM_COPY will probably work, however, if what you are targeting is something like a custom control that does not implement WM_COPY then it will not work.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> If it doesn't matter, it's antimatter.<
|
|
|
|
|
In Release mode with VS2008,
Why "var" prints "Whats up" instead of "newval"
It crashes in debug mode. I guess the reason might be the auto-memory allocation is "read-only". If I use char *var = new char[15] then it works fine.
#include <stdio.h>
#include <conio.h>
#include <string>
int main()
{
char *var = "\nWhats Up";
strcpy(var, "newval");
printf(var);
getch();
return 0;
}
|
|
|
|
|
When you create var in this way it is pointing to a constant string so your strcpy() command is not allowed. What you should code is:
char *var = "\nWhats Up";
var = "newval";
char var[] = "\nWhats Up";
strcpy(var, "newval");
although in the second case you could easily overwrite the buffer if you are not careful.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Richard MacCutchan wrote: although in the second case you could easily overwrite the buffer if you are not careful.
Did you mean overrun, didn't you?
BTW: Good answer, my 5.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Well spotted!
Odd how it looked quite sensible when I wrote it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
First off, I'm real new to C++ so hopefully I state things right and I'm in the correct forum.
I'm tinkering with some code to use the CreateProcessWithTokenW function (http://msdn.microsoft.com/en-us/library/windows/desktop/ms682434(v=vs.85).aspx). Now, everything works just fine when I run it on Windows 7. But if I run it on XP, it bombs out with an error message about the procedure entry point not being located in the dynamic link library ADVAPI32.dll.
So what do I need to do to either make this work on XP, or else drop back to using CreateProcessAsUser on Windows XP, but still use CreateProcessWithTokenW on Windows 7?
|
|
|
|
|
According to this page[^], it is not supported on XP. The minimum supported client is Windows Vista.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Hi,
I am very happy to hear that you went straight to MSDN to get your answers. That is definitely a working recipe for becoming a better software engineer. When you are reading these MSDN function descriptions... always scroll to the bottom... the MSDN almost always gives which library the function is being exported from (in this case Advapi32.dll) and the minimum operating system/service pack required. You have obviously already discovered that the minimum OS is Vista for this function.
If you already have an access token then you should use the CreateProcessAsUser function[^]
Lucidation wrote: So what do I need to do to either make this work on XP, or else drop back to using CreateProcessAsUser on Windows XP, but still use CreateProcessWithTokenW on Windows 7?
I would personally recommend using CreateProcessAsUser for both scenarios. Why create two code paths? CreateProcessAsUser should work for XP all the way to Win7Sp1.
Best Wishes,
-David Delaune
|
|
|
|