|
It sounds like the problem is at the beginning. Setting a breakpoint at the beginning of ServiceMain _after_ the service is started won't do you any good since that code has already executed. You need to use the DebugBreak function at the very start of your ServiceMain. It will force a breakpoint and the OS will allow you to select a debugger to attach to the process - in this case your service. You can then debug your startup logic which, by your description, is where your problem is.
I don't know that your code doesn't have any errors. In a visual inspection, I don't see one but I don't know what your problem domain is and your thinking about how your code solves that problem. I don't have your whole program nor do I want you to post it. Your problem is at the beginning - you need to debug that, conparing your intended logic flow with what your code actually does. The only way to debug the beginning of a service is by using the DebugBreak .... or coding an infinite loop and attaching the debugger as you are already doing and then breaking the loop. Use DebugBreak
Judy
|
|
|
|
|
Thanks Judy!
I kept DebugBreak() in the MyServiceMain()... and when i traversed throughout the debug.. the problem was same what i told before.. the
usbDB.OpenEx(szConnectString_USB,CDatabase::noOdbcDialog);
is not getting opened and therefore the catch block is getting executed. Whereas i want the database to be connected.
I don know... how to solve..lets hope for the any other right way.
Thanks in Advance
Anee
|
|
|
|
|
That I can't help with - databases are not my thing. At least now you know that it is exclusively a database problem and not a service problem. Make sure you step into the Open and trace it as far into the guts of the provided source code as you can. It might give some help on finding the problem.
One thing to be aware of when running as a service is your permissions. You are not a "normal" program. You are running in the Local System account. You haven't mentioned which OS this is on. XP is usually pretty good about letting services do all the usual things (excepting UI). Vista is much more restrictive.
Good luck!!
Judy
|
|
|
|
|
Great Thanks for helping me out in fixing the exact problem area.
And now moving towards the solution part, i am using the process explorer to get the exact information of the services and processes and their threads,DLLs etc.
After placing DebugBreak()... in the catch block of :
try{
DebugBreak();
usbDB.OpenEx(szConnectString_USB,CDatabase::noOdbcDialog);
}
catch(CException *e)
{
WriteIntoLogFile("db open Exception in the User_USB_login_data");
DebugBreak();//Here the breakpoint is getting triggered at last. and the error window is showing like this:
}
Error window displays:
Windows has triggered a breakpoint in MyService.exe.
This may be due to a corruption of the heap, and indicates a bug in MyService.exe or any of the DLLs it has loaded.
The output window may have more diagnostic information
.............................
my development environment is Windows XP and VC++.Net 2005
Any ideas..pls!
Thanks in Advance
Anee
|
|
|
|
|
You should be hitting the DebugBreak in the try section. When the Windows message appears, there should be a "debug" option / button somewhere in the window. If you select that, you should get a window from the Visual Studio Just-In-Time debugger listing the possible debuggers to use. Select Visual Studion 2005 - if you have your service project already open, it should go right to the line with the DebugBreak. Use "set next statement" to skip to the next line of code. Is this not happening? To check the obvious, you are running a debug build of your service, yes? Make sure Just-In-Time debugging is enabled (Tools -> OPtions -> Debugging).
Judy
|
|
|
|
|
|
Hello,
After debugging what i found is that, the CDBException at the following statement raises an exception:
cdb.openEx(szConnectstring, CDatabase::noODBCDialog)
And the message throwed is: "Data source name not found and no default driver specified"
Whereas when i check for this dsn's status..from control panel the test connection is showing success. And also i am using the same dsn and same database from other VC++.Net2005 application ( this is not a windows service application), this application is getting connected to MySQL database using the same dsn and also able to read the records from one of the tables there(which shown in the applications UI window). I am not creating the windows service using the .Net framework. I am creating the my windows service application using the winsvc.h and advapi32.dll.
I guess, since the application from which i am trying to connect to MySQL database is a windows service application, so probably causing some problem (due to some hidden windows internals..issues).. which i am unable to fix...
Can anybody.. help me out by giving the clues..
Thank you..
Anee
|
|
|
|
|
Thanks to all specially to JudyL_FL.. who tried to help me out in fixing my problem.
And there is a good news, the problem got fixed.... .
Actually i am not sure that whether i m right or not in my analysis.
What i did to solve this:
I just created System DSN now and everything was same. And it worked fine, without any problem. Before this i using User DSN.
The cause of problem would be: What i guess is, since the windows service which i am developing is a system service so it is failing to open MySQL db through the User DSN. Am i right? or is there anything else which is causing the problem...
Thanks in advance.
Anee
|
|
|
|
|
in some program i always see "#pragma pack(1)" included in Header. what is the role of #pragma pack(1).
Thanks
Monica
|
|
|
|
|
mo_nica881 wrote: what is the role of #pragma pack(1).
Specifies packing alignment (e.g., 1 byte) for structure and union members.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
It forces structures member alignment to 1 byte. By default, the members of the structure are aligned on 8 bytes boundaries. With this option, you force the members to be aligned on 1 byte boundaries (so it makes your structure more compact in memory but less efficient for read/write operations because some members will need to operations to be updated).
More info here[^]
|
|
|
|
|
mo_nica881 wrote: in some program i always see "#pragma pack(1)" included in Header. what is the role of #pragma pack(1).
It's useful to disable structure member alignment. Value of 1 disables any alignment...
For eg:
struct aligntest
{
char aChar;
int nNum;
};
Normally sizeof( aligntest ) will return 8 but the actual size is 5. Extra 3 bytes is used for padding. This is done for efficiency sake.
This could be a problem if you are using functions like memcpy to copy native type values into structures for splitting them up and you want each part to be named...
For eg:
#pragma pack( push, 1 ) // Set alignment to 1
struct IntParts
{
BYTE byPart1;
BYTE byPart2;
BYTE byPart3;
BYTE byPart4;
};
#pragma pack( pop ) // Restore previous settings
int nSplit = 123213;
IntPart ip = { 0 };
memcpy( &ip, &nSplit, sizeof( ip ));
The above operation will be dangerous with padding since sizeof of int is 4 and the sizeof the structure should also be 4, hence you have to disable padding using #pragma pack( push, 1 ) and when you are done with the setting write another #pragma pack( pop ) which resets the setting.
You should not use 1 alignment always except for above reasons.
|
|
|
|
|
|
sk8er_boy287 wrote: I'm pretty much sure (from experience) that sizeof always returns the size of the type of structure (5 for your code sample). sizeof doesn't care about memory alignment.
Wrong. Test and see.
|
|
|
|
|
sk8er_boy287 wrote: ...(5 for your code sample).
Only if #pragma pack(1) is present. By default, it will have a size of 8.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I've just tested and you're right. I've always trusted sizeof to give me the right size of any type of structure. I find this behavior kind of weird.
However, I've also tested with arrays and the size of a single element of an array includes the padding. So there's no problem there, other than a lot of useless padding for large arrays.
I wonder what this code would do (try to copy 8 bytes into 3 ) :
#pragma pack( push, 1 ) // Set alignment to 1
struct IntParts1
{
BYTE byPart1;
BYTE byPart2;
BYTE byPart3;
};
#pragma pack( pop ) // Restore previous settings
struct IntParts2
{
BYTE byPart1;
BYTE byPart2;
BYTE byPart3;
};
IntParts1 ip1 = {0, 1, 2};
IntParts2 ip2 = {0, 1, 2};
memcpy( &ip1, &ip2, sizeof( ip1 ));
|
|
|
|
|
sk8er_boy287 wrote: I wonder what this code would do (try to copy 8 bytes into 3) :
In your example, both ip1 and ip2 are the same size (3 bytes).
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Can anyone explain that? Shouldn't the second structure be allocated using the default 8-byte alignment?
Here's another example which should copy 8 bytes into 5:
#pragma pack( push, 1 ) // Set alignment to 1
struct IntParts1
{
char byPart1;
int byPart2;
};
#pragma pack( pop ) // Restore previous settings
struct IntParts2
{
char byPart1;
int byPart2;
};
IntParts1 ip1 = {0};
IntParts2 ip2 = {0};
memcpy( &ip1, &ip2, sizeof( ip1 ) );
printf( "%d, %d\n", sizeof( IntParts1 ), sizeof( IntParts2 ) );
And don't tell me they're both 5 bytes in size because i tested this time!
|
|
|
|
|
sk8er_boy287 wrote: Here's another example which should copy 8 bytes into 5:
Actually, you're example would only copy 5 bytes.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Something not considered here is the effect on the alignment of each member within the struct.
This makes your memcpy() from one type to another even more dangerous...
#pragma pack( push, 1 ) // Set alignment to 1
struct IntParts1
{
char byPart1;
int byPart2;
};
#pragma pack( pop ) // Restore previous settings
struct IntParts2
{
char byPart1;
int byPart2;
};
As DavidCrow mentioned, you've copied sizeof( ip1 ) (5) bytes.
This would cause you to lose 3 bytes of the source byPart2 member...not good.
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
I think I understand now. Thanks.
Sounds to me like it's best not to use #pragma pack at all. It hasn't bothered me until now and it doesn't seem like it has any real usage.
I don't know if MSDN says anything about this but I'm pretty sure they're aligned on byte boundaries. I could've easily created my own struct as above by mistake, and copied it's contents to an API structure. No idea what would've happened.
I suppose problems can be avoided if you don't copy your own data structures into the API ones or, if you must, copy each member separately.
|
|
|
|
|
I think of it the same way as with classes - A binary copy of one class type to another isn't
necessarily safe. That's what copy constructors and assignment operators are for.
To me, #pragma pack is only useful for cross platform/language situations. In the past I could be
assured that any language could at least deal with byte (1) packing. This especially applied
when mixing with assembly language.
For Win32, I believe the default packing of 8 is used.
For MFC it may be 4...there's so many damn nested header files it's hard to trace
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
I stated "For Win32, I believe the default packing of 8 is used."
I believe that's wrong Actually it varies all over the place. 4 is used in general it seems
but there are many cases of 2 and 1.
Here's a link to an article by an old MS programmer: Alignment (part 2): Packing[^]
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Hi,
I'd like to make my CFrameWnd subclass not resize any smaller than a certain size. Everywhere I web-search, I see that the suggested way to do this is:
void CWndDerived::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// set the minimum tracking width
// and the minimum tracking height of the window
lpMMI->ptMinTrackSize.x = 200;
lpMMI->ptMinTrackSize.y = 150;
}
I type this into my (very simple) app, and set a breakpoint at the start of this function. It is never called.
Is this method still valid? (under Visual Studio 2005 c++)
Thanks,
Max
|
|
|
|
|
maxmaven wrote: CWndDerived
Are you sure this class window is window you are trying to resize ?
A quick test in simple SDI app, shows result as expected.
|
|
|
|