|
As mentioned in the other answer, you will need to run regsvr32 as administrator on Windows 7 to register the ocx control.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Chartfx, first time I know it.
|
|
|
|
|
Hi all:
I have run the program successfully in the Linux
but it failed in the solaris, the program will exit after creating process.
I don't known the different between the solaris and linux.
The output when running the programm:
9
10
2
3
4=3374
9
10
1=3373
The part code as following.
// unix daemon
#include <fcntl.h>
#include <sys resource.h="">
#include <stdio.h>
#include <stdlib.h>
#include <sys types.h="">
#include <unistd.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <sys stat.h="">
#include "SPSServiceApp.h"
#define LOCKFILE "/var/run/SPSService.pid"
#define LOCKMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
void daemonize(const char* cmd)
{
int i, fd0, fd1, fd2;
pid_t pid;
struct rlimit rl;
struct sigaction sa;
// Clear file creation mask
umask(0);
// Get maximum number of file descriptors
if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
{
fprintf(stderr, "%s: can't get file limit", cmd);
exit(1);
}
if ((pid = fork()) < 0)
{
fprintf(stderr, "%s: can't fork", cmd);
exit(1);
}
else if (pid != 0) //parent
{
printf( "1=%d\n", getpid());
//printf( "1ppid=%d\n", ggetpid());
exit(0);
}
setsid();
printf( "2\n");
// Ensure future opens won't allocate controlling TTYs.
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
if (sigaction(SIGHUP, &sa, NULL) < 0)
{
fprintf(stderr, "%s, can't ignore SIGHUP", cmd);
exit(1);
}
printf( "3\n");
if ((pid = fork()) < 0)
{
fprintf(stderr, "%s: can't fork", cmd);
exit(1);
}
else if (pid != 0) //parent
{
printf( "4=%d\n", getpid());
//printf( "4ppid=%d\n", ggetpid());
exit(0);
}
printf( "5\n");
if (rl.rlim_max == RLIM_INFINITY)
{
rl.rlim_max = 1024;
}
for (i = 0; i < rl.rlim_max; ++i )
{
close(i);
}
printf( "6\n");
fd0 = open("/dev/null", O_RDWR);
printf( "7\n");
fd1 = dup(0);
fd2 = dup(0);
if (fd0 != 0 || fd1 != 1 || fd2 != 2)
{
printf( "8\n");
exit(1);
}
}
int lockfile(int fd)
{
struct flock fl;
fl.l_type = F_WRLCK;
fl.l_start = 0;
fl.l_whence = SEEK_SET;
fl.l_len = 0;
return(fcntl(fd, F_SETLK, &fl));
}
int already_running(void)
{
int fd;
char buf[16];
fd = open(LOCKFILE, O_RDWR | O_CREAT, LOCKMODE);
if(fd < 0)
{
exit(1);
}
if (lockfile(fd) < 0)
{
if (errno == EACCES || errno == EAGAIN)
{
close(fd);
return(1);
}
exit(1);
}
ftruncate(fd, 0);
sprintf(buf, "%ld", (long)getpid());
write(fd, buf, strlen(buf) + 1);
return(0);
}
int main(int argc, char* argv[])
{
char* cmd;
struct sigaction sa;
printf("9\n");
if ((cmd = strrchr(argv[0], '/')) == NULL)
{
cmd = argv[0];
}
else
{
++cmd;
}
// Become a daemon
printf("10\n");
daemonize(cmd);
printf("11\n");
// Make sure only one copy of the daemon is running
if (already_running())
{
exit(1);
}
printf("12\n");
sa.sa_handler = SPSServiceApp::sig_term;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGHUP);
sa.sa_flags = 0;
if(sigaction(SIGTERM, &sa, NULL) < 0)
{
exit(1);
}
printf("13\n");
sa.sa_handler = SPSServiceApp::sig_hup;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGTERM);
sa.sa_flags = 0;
if(sigaction(SIGHUP, &sa, NULL) < 0)
{
exit(1);
}
wxEntry(argc, argv);
printf("14\n");
exit(0);
}
|
|
|
|
|
The first thing you should do is to edit your question and put proper <pre> tags around your code so it is readable. The second thing is to explain exactly what the program is doing and where it terminates.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi. I have assignment to find difference between Min and Max of an array of 5 numbers. I did some work, but after compiling - my program does not run, it just stops working.. Can you help me, where is my mistake ? Array values needs to be double.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int size;
double array [i];
double min;
double max;
double difference;
printf("Enter the size of the array: ");
scanf("%d",&size);
printf("Enter %d elements in to the array: ", size);
scanf("%d",&array[i]);
max = array[0];
for (i=0; i<size; i++)
if (max < array [i])
max = array [i];
{
printf("Maximum value is: %d\n",max);
}
min = array [0];
for (i=0; i<size; i++)
if (min>array[i])
min = array [i];
{
printf("Minimum value is: %d\n",min);
}
difference = max - min;
printf ("Difference between Min and Max values is %d\n", difference);
system("PAUSE");
return 0;
}
|
|
|
|
|
I've not looked terribly close, but please start by putting { }'s around your for loop blocks.
for example;
for (int i = 0; i < size; i++)
{
}
|
|
|
|
|
Mikerush7 wrote: Array values needs to be double.
then this is wrong:
Mikerush7 wrote: scanf("%d",&array[i]);
|
|
|
|
|
(1)Quote: int i; // element in array
int size; // size of array
double array [i]; // number of elements in array
You shouldn't do that, even if the compiler allows the C99 extension (see, for instance "Arrays of Variable Length"[^]) since variable i is NOT initialized.
You should either allocate a fixed size array, e.g
double array[5];
or dynamically allocate the array, based on user choice, e.g.
double * array;
int size;
printf("Enter the size of the array: ");
if ( scanf("%d",&size) != 1 || size < 1)
{
return -1;
}
array = (double) * malloc( size * sizeof(double));
if ( ! array )
{
return -1;
}
(2) Quote: printf("Enter %d elements in to the array: ", size);
scanf("%d",&array[i]);
You should prompt the user for every item of the array, that is you should use a loop:
int n;
for (n=0; n<size; n++)
{
printf("Enter elemnt %d of %d in to the array: ", (n+1), size);
if ( scanf("%f",&array[n]) != 1)
{
}
}
(3) NOTE THIS IS NOT AN ERROR
Quote: for (i=0; i<size; i++)
if (max < array [i])
max = array [i];
{
printf("Maximum value is: %d\n",max);
}
min = array [0]; // let first number in array be minimum
for (i=0; i < size; i++)
if (min > array[i])
min = array [i];
{
printf("Minimum value is: %d\n",min);
}
You didn't need two separate loops in order to find max & min values:
double min = max = array[0];
for (i=0; i<size; i++)
{
if (min>array[i])
min = array [i];
if (max<array[i])
max = array[i];
}
printf("Minimum and maximum values are: {%f, %f}\n",min, max);
(4)
Quote: printf ("Difference between Min and Max values is %d\n", difference);
Here, as usual you used %d instead of %f for double format specifier. Change to
printf ("Difference between maximum and minimum values is %f\n", difference);
Veni, vidi, vici.
|
|
|
|
|
Since this is your assignment, you probably want to write the algorithm yourself.
But just so you know, C++ already has an implementation for this algorithm.
So a C++ program would be as follows -
#include <algorithm>
int main()
{
double arr[7] = { 5.6, 3.4, 9.8, 1.2, 5.5, 9.9, 4.9 };
std::pair<double*, double*> minmax = std::minmax_element(&arr[0], &arr[7]);
double min = *minmax.first;
double max = *minmax.second;
return 0;
}
With the new C++ standard, you could write this in a more generic way -
#include <algorithm>
int main()
{
double arr[7] = { 5.6, 3.4, 9.8, 1.2, 5.5, 9.9, 4.9 };
auto minmax = std::minmax_element(std::begin(arr), std::end(arr));
auto min = *minmax.first;
auto max = *minmax.second;
return 0;
}
|
|
|
|
|
You canot write this way
double array [i]; beacuse here i is not initialized. so when compiling compiler will give the error like
1. Array unknown size
2. cannot allocate an array of constant size size 0.
2. expected constant expression.
so you can write this way
double array[10]
or dynamically allocate the array.
printf("Enter %d elements in to the array: ", size);
scanf("%d",&array[i]);
why you are write in this way? you just think how to read the required number of elements in to array without a loop? so reading of this array with in a loop, ie see below
printf("Enter %d elements in to the array: ", size);
for( i = 0; i < size; i++ )
{
scanf("%d",&array[i]);
}
also an important note when writing the code is give meaning full name for variable. because this will increase the readability of your code. Also keep a coding standard when writing code.
Next is the logic which is used to find minimum and maximum value from the array.
you can optimise your code like this way
double Min = array[0];
double Max = array[0];
for( i = 0; i < size; i++ )
{
if( Max < array[i] )
{
Max = array[i];
}
if( Min > array[i] )
{
Min = array[i]
}
}
so code optimization is important when coding in large projects.
Thanks
|
|
|
|
|
Thank you for your help !
|
|
|
|
|
Hello,
I like to delete the key 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\LEGACY_HTTP\0000' programatically in C++. I get Error 5 which is Access Denied. I tried calling ACL functions but i could not succeed. Can any one help me by giving code snipped through which i can delete the above mentioned Registry Key.
|
|
|
|
|
You must open the parent key by calling RegOpenKeyEx() with the DELETE access right. Because the key is in HKLM, your code must be also executed as administrator.
|
|
|
|
|
Thank you. I tried this option aswell, I could able to Delete keys under HKLM\Software\ but could not able to delete the key that i mentioned. I think i need to get access rights beyond Administrator rights inorder to delete the Registry enrty that i mentioned.
modified 24-Oct-12 11:32am.
|
|
|
|
|
You are trying to delete a system key. Such keys can be only deleted by the owner (the user SYSTEM).
If you really want to delete such a key (you should know what you are doing), you must change the access rights of the key (e.g. by allowing full access for administrators).
|
|
|
|
|
I checked my Administrator has Full right Access. But Still i could not delete the registry Key that i Mentioned.
|
|
|
|
|
|
I have my custom listview control:
dwStyle = WS_CHILD|WS_VISIBLE|WS_BORDER|CBS_DROPDOWN;
When I am using mouse to select value in combobox, dropdown is just closed (but combobox is not destroyed) and CBN_SELENDOK meessage is not send.
Does anyone knows why ?
|
|
|
|
|
Where and how did you try to process the message?
I ask because the message is send to the parent of the combo box. If you want to handle the message by your combo box class you can use message reflection:
BEGIN_MESSAGE_MAP(CMyComboBox, CComboBox)
ON_CONTROL_REFLECT_EX(CBN_SELENDOK, OnCbnSelendok)
END_MESSAGE_MAP()
BOOL CMyComboBox::OnCbnSelendok()
{
return FALSE;
}
|
|
|
|
|
actually it is so
m_editData.hwndEdit = CreateWindowEx(0,
_T("COMBOBOX"),
_T(""),
dwStyle,
rect.left, rect.top,
rect.right-rect.left, 150,
hwnd,
0,
m_hInstance,
0);
and then
m_editData.defEditWndProc = (WNDPROC)SetWindowLongPtr(m_editData.hwndEdit, GWLP_WNDPROC, (LONG_PTR)MCLV_EditCtrlWndProc);
SetWindowLongPtr(m_editData.hwndEdit, GWLP_USERDATA, (LONG_PTR)this);
so it has its own handling
|
|
|
|
|
So you are not using MFC and can not use the MFC message reflection.
Then you must handle the message (WM_COMMAND , CBN_SELENDOK in high order word of WPARAM , combo box window handle in LPARAM ) in the window procedure of your m_editData window because that is the parent of the combo box.
Your MCLV_EditCtrlWndProc() function set for the combo box window will not receive the message.
|
|
|
|
|
You were right parent should pass that message...
|
|
|
|
|
I am trying to compile a chunk of C++ code on VS 2008.
I keep experiencing the LNK2001 error about the symbol _recalloc, for unknown reasons.
I know the warning means that some library is missing , but this is not the case. I put in the right #include
(which is , according to MSDN, both <stdlib.h> and <malloc.h>), I specified the path to atlsd.lib (which seems to be the library the linker looks for when operating), I even added the library to the additional dependencies on the linker configuration but nothing seems to change.
This is my first time using C++ on VS .net ( I have been using VC++ 6.0 previously), so I sure lack experience and knowledge , but I start wondering whether switching to .net wasn't a bad mistake .....
Any idea ?
thank you
|
|
|
|
|
I'm not sure exactly what you are doing here (it does not sound like you are creating a .NET program), but the _recalloc() function is defined in the standard C library. I just added a call into a small C++ program and the linker did not need any extra library definitions to find it. Maybe you need to give a few more details about your code.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
You are right Richard my post was not clear, I am going to explain . I wrote a small program which uses the CA2X () conversion class (need to turn ascii strings to unicode).
The linker error I get shows in the detail that the method ATL::AtlConvAllocMemory() , which calls _recalloc() , is the source of the error.... since , this method is contained in "atlsd.lib" (I suppose) that's why I mentioned it ... The method ATL::AtlConvAllocMemory() is in turn called by CA2X(), hence the error.
Now, I am wondering what can be wrong since I included everything MSDN is asking me for, both header and .lib files .
I have atlbase.h and atlconv.h in right places, and both malloc.h and stdlib.h are included beforehand.
But whatever I try to change, it seems the outcome doesn't change.
I am quite clumsy with this environment, I had experiences in c# and minor ones in vb .net , other than VC++ 6.0 so I am new at this .... I am not quite sure but I guess I am not using the framework here, that is I am compiling to native code, since I can't find the /clr switch anywhere in the settings (but , as I told you, I am not sure ....).
Thank you for answering
|
|
|
|
|