|
|
Hi Cool_Dev,
I roughly had a glance on the discussion thread just now. In the thread, they came out with the solution using manifest file, right?
Answering to your question: Yes, I am on Windows 7 32-bit platform. My code is to be compiled with VC++6 and WDK 6000. So manifest files might not be the solution to this issue ... I guess.
Maxwell Chen
|
|
|
|
|
That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument.
Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.
|
|
|
|
|
Cool_Dev wrote: That thread says that the error code 5 can be ERROR_CANTWRITE also. Have a look into it. you can ensure it by checking the value got in in PHKEY argument.
Also try using KEY_ALL_ACCESS Or KEY_WOW64_64KEY in RegOpenKeyEx.
Hi Cool_Dev,
1) The name KEY_WOW64_64KEY is not defined in VC++ 6. So I did not add it since the compiler said "undeclared identifier".
2) RegOpenKeyEx returns value 0 in the PHKEY argument.
3) I have been using KEY_ALL_ACCESS all the time.
4) During run-time seen on the debugger, ERROR_ACCESS_DENIED is 0x0005 and ERROR_CANTWRITE is 0x03F5 .
Please refer to the screenshot[^] on VC++2005 remote debugger.
Maxwell Chen
|
|
|
|
|
Hi Maxwell,
Its not an answer but I have one doubt.
Are you sure that your application is launched with admin priviledge ?? I am also doing the same in Windows Service and it is working fine in XP, Windows 7 and Vista.
If my application is not lauched with admin priviledge than i get access denied error else it is working fine.
I believe in LOVE AT FIRST SIGHT...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
Hi Shilpi,
Shilpi Boosar wrote: Are you sure that your application is launched with admin priviledge ??
I think so. I right-click on the Command Prompt shortcut, and choose "Run as Admin", to open a DOS-box. And then I type the command:
MyService.exe -r
to setup and start the service.
Maxwell Chen
|
|
|
|
|
I don't think that means the service will run as admin, though.
When the service is installed, it determines what user it will run as.
Open Task Manager, find the process that represents your service and check what user account it is running under.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard Andrew x64 wrote: Open Task Manager, find the process that represents your service and check what user account it is running under. Hi Richard,
My service is running under the name SYSTEM .
(The logon session user account is "user ".)
Maxwell Chen
|
|
|
|
|
Nops if He open command prompt as "run as admin" mode and run application than it means that its application is also run as admin mode.
I believe in LOVE AT FIRST SIGHT...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
#include <windows.h>
#include <iostream>
using namespace std;
struct Detail{
wchar_t Name[25];
long Age;
wchar_t Address[100];
};
struct Student{
Detail st;
DWORD code;
};
int main()
{
Student st;
}
how to write and read structure to a file using WriteFile() and ReadFile().
Some Day I Will Prove MySelf :: GOLD
modified on Saturday, February 19, 2011 9:43 AM
|
|
|
|
|
Something like
DWORD dwWritten;
BOOL result = WriteFile(hFile, &st, sizeof st, &dwWritten, NULL);
Use a similar form to read it back.
I must get a clever new signature for 2011.
|
|
|
|
|
#include <windows.h>
#include <conio.h>
#include <iostream>
using namespace std;
struct Detail{
wchar_t Name[25];
long Age;
wchar_t Address[100];
};
struct Student{
Detail detail;
DWORD code;
};
int main()
{
DWORD BytesWritten=0, BytesRead=0;
Student st,read;
st.code =1;
st.detail.Name = TEXT("Williams");
st.detail.Age = 25;
st.detail.Address = TEXT("B-33 Lane 5");
HANDLE hFile = CreateFile(TEXT("C:\\demo.txt"),GENERIC_READ | GENERIC_WRITE,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
if (hFile != INVALID_HANDLE_VALUE)
{
WriteFile(hFile,&st,sizeof(Student),&BytesWritten,0);
ReadFile(hFile,&read,sizeof(Student),&BytesRead,0);
CloseHandle(hFile);
cout<<read.code<<endl;
cout<<read.detail.Name;
}
else
{
cout<<"Error! Cannot Open File";
exit(1);
}
_getche();
return (0);
}
when executing this code following error occurs.
Error 1 error C2440: '=' : cannot convert from 'const wchar_t [9]' to 'wchar_t [25]'
Error 2 error C2440: '=' : cannot convert from 'const wchar_t [12]' to 'wchar_t [100]'
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
goldenrose9 wrote: st.detail.Name = TEXT("Williams");
st.detail.Address = TEXT("B-33 Lane 5");
You probably meant to use _tcscpy() here instead.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: You probably meant to use _tcscpy() here instead.
This works like a charm
_tcscpy(st.detail.Name,TEXT("Williams"));
_tcscpy(st.detail.Address,TEXT("B-33 Lane 5"));
But another problem arises cannot set values in long and DWORD variables
struct Detail{
wchar_t Name[25];
long Age;
wchar_t Address[100];
};
struct Student{
Detail detail;
DWORD code;
};
Student st;
st.code = 1;
but st.code stores a default value of -16843010 and same problem with long data type st.Details.Age = 25 stores 65278, instead of 25.
MODIFIED:
_tcscpy_s() now works. i was making a small mistake. Now it works..
_tcscpy_s(st.detail.Name,_tcslen(st.detail.Name),TEXT("WILLIAMS"));
Some Day I Will Prove MySelf :: GOLD
modified on Wednesday, February 16, 2011 10:43 PM
|
|
|
|
|
goldenrose9 wrote: why error is occurring in _tcscpy_s()
Hard to say since you did not indicate what the error was.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Try ZeroMemory
Student st,read;
ZeroMemory(&st,sizeof(st));
I believe in LOVE AT FIRST SIGHT...
Bcoz I have loved my Mother...
even since I opened my eyes...(ICAN)
|
|
|
|
|
To OP: This is only meaningful if you don't intend to initialize every member separately.
|
|
|
|
|
goldenrose9 wrote: i was making a small mistake.
And you still are. _tcslen() does not tell you the size/capacity of Name , but rather how many characters it is currently holding.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
yes you are right. but when i use
_tcscpy_s(st.detail.Name,sizeof(st.detail.Name),TEXT("WILLIAMS"));
stack around st get corrupted.
moreover when i initialize st with
st.code =1;
st.detail.Age = 25;
then the value is changed to
st.code = 4278124286
st.detail.Age = -16843010
i had intialized the st as given
st.code =1;
st.detail.Age = 25;
_tcscpy_s(st.detail.Name,sizeof(st.detail.Name),TEXT("WILLIAMS"));
_tcscpy_s(st.detail.Address,sizeof(st.detail.Address),TEXT("BB-33 LANE 5"));
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
Have you considered:
st.code = 1;
st.st.Age = 25;
_tcscpy_s(st.st.Name, sizeof(st.st.Name), TEXT("WILLIAMS"));
_tcscpy_s(st.st.Address, sizeof(st.st.Address), TEXT("BB-33 LANE 5"));
For clarities sake, you might consider renaming the st member of Student .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
whenever st.code and st.st.Age is initialized with any value the result is,
st.code = 4278124286
st.detail.Age = -16843010
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
You need to look more closely at the code snippet I provided. You should not be assigning or referencing st.Detail . In your Student structure, Detail is a type of structure, not an instance of one.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
please give a small example.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
on using
st.code = 1;
st.st.Age = 25;
_tcscpy_s(st.st.Name, sizeof(st.st.Name), TEXT("WILLIAMS"));
_tcscpy_s(st.st.Address, sizeof(st.st.Address), TEXT("BB-33 LANE 5"));
following error occurs.
Error 1 error C2039: 'st' : is not a member of 'Student'
Error 2 error C2228: left of '.Age' must have class/struct/union
Some Day I Will Prove MySelf :: GOLD
|
|
|
|