|
A stated problem with a good solution is never a waste of our time, in my opinion. If they have not already, then one of the guys who likes compiling solution faqs will include this.
Good work!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Hello,
I have an OCX that works on the PC built with VS6.0. It registers correctly and can be used to write more C++ applications with it.
The OCX has been ported to Embedded platforms(PPC 2003 SE). It builds via eVC++ 4.2 with 0 Error(s) 0 Warning(s) for PocketPC 2003 SE for the processor I'm using. The "build" output-window says it registers correctly. I'd love to say it works; however, I can't prove it.
Both IDE's say it registered correctly.
Here's the problem:
I open the eVC project I'm going to be using this OCX with. I go to Project->Add to Project->Components and Controls and attempt to add control - my shiney new OCX. (I imagine that eVC desires the embedded OCX vs the PC OCX - though, admittedly, I've tried them both.)
Every time I try to add the control I get the following message:
"Failed to find desktop version of control in registry. Please verify that this control has been successfully registered on the desktop."
So, I ask, what am I doing wrong here?
|
|
|
|
|
~!^)&*(^!@#)&*^~
I found several problems.
First problem was PEBKAC. I was navigating to the build output directory of the ActiveX control and not the registered components directory one would find their registered controls in. But, why would I do that, you ask? Well, every time I navigated to the registered controls directory, it was empty. Which leads me to the second problem.
eVC defaults the developer to the 'Registered ActiveX controls' for the embedded development directory:
C:\Program Files\Microsoft eMbedded C++ 4.0\Common\EVC\Gallery\Registered ActiveX Controls
It *wants* the PC's! 'Registered ActiveX Controls' directory.
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Gallery\Registered ActiveX Controls
Is it just me or is this counter-intuitive?
So, I navigate there. It too is empty....huh!?
Thirdly, eVC doesn't (or, isn't, on my PC) displaying the Visual Studio 'Registered ActiveX Controls' directory *unless* VS6 is open and is being 'fooled' into thinking someone is trying to 'add a Component or Control' for a VS6 project.
So, there you go. I'm totally disgusted.
|
|
|
|
|
Hi,
I'm new to C++ programming, and i'm having a problem passing pointer to array.
Here is the code:
typedef struct {
int i;} tpteste;
int test (tpteste * l)
{
l = new tpteste[4];
l[0].i = 99;
l[1].i = 98;
l[2].i = 97;
l[3].i = 96;
return 0;
}
int doNothing(void)
{
int j = 0;
tpteste * w;
j = test(w);
return 0;
}
When the "test" function returns, there's nothing in the pointer "w". It does not change it's value.
It may be a dummy question, but i'm having a bad time here with it...
Thanks in advance.
Renato Carvalho.
|
|
|
|
|
wrote: int test (tpteste * l)
{
You need to pass here pointer to pointer as argument. Your function should look like
int test (tpteste ** l)
{
*l = new tpteste[4];
l[0]->i = 99;
l[1]->i = 98;
l[2]->i = 97;
l[3]->i = 96;
(*l)[0].i = 99;
(*l)[1].i = 98;
(*l)[2].i = 97;
(*l)[3].i = 96;
return 0;
}
-- modified at 10:27 Wednesday 14th February, 2007
-- modified at 23:19 Wednesday 14th February, 2007
|
|
|
|
|
prasad_som wrote: *l[0].i = 99;
Not quite.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Result of trying to be fast in reply.
Anyway, OP's problem was addressed in my reply.
|
|
|
|
|
prasad_som wrote: Anyway, OP's problem was addressed in my reply.
Actually it wasn't. You'll notice that the first two assignments in test() "appear" to work, but the last two will fail miserably.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I tried the changes, but it did not compile. Then i changed the assignments at function "test" to "l[X]->i = 99;" and it compiled.
But, in fact, when it runs, the 3ª instruction fails with an access violation.
The code now looks like this:
typedef struct {
int i;} tpteste;
int test (tpteste ** l)
{
*l = new tpteste[4];
l[0]->i = 99;
l[1]->i = 98;
l[2]->i = 97;
l[3]->i = 96;
return 0;
}
int doNothing(void)
{
int j = 0;
tpteste * w;
j = test(&w);
return 0;
}
|
|
|
|
|
Renato Carvalho wrote: But, in fact, when it runs, the 3ª instruction fails with an access violation.
Of course it will. That's what I was trying to "hint" to Prasad.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Agree. Again, it was wrong way of accessing array.
DavidCrow wrote: prasad_som wrote:
Anyway, OP's problem was addressed in my reply.
Actually it wasn't
You can see, OP's was facing problem due to passing pointer(by value ofcourse), and allocating memory for it inside function, which I corrected by sugggesting pointer to pointer(**) way. I was underlining that point. Modiefied original reply to run correctly.
|
|
|
|
|
That's the result:
int test (tpteste ** l)
{
*l = new tpteste[4]; //error C2228: left of '.i' must have class/struct/union type
*l[0].i = 99; //error C2228: left of '.i' must have class/struct/union type
*l[1].i = 98; //error C2228: left of '.i' must have class/struct/union type
*l[2].i = 97; //error C2228: left of '.i' must have class/struct/union type
*l[3].i = 96; //error C2228: left of '.i' must have class/struct/union type
return 0;
}
int doNothing(void)
{
int j = 0;
tpteste * w;
j = test(w); //error C2664: 'test' : cannot convert parameter 1 from 'tpteste *' to 'tpteste ** '
return 0;
}
In fact, it did not compile. But i will try to work on "pointer to pointer" solution. It's been a long time since i studied C at graduation, and i think a forgot some important points.
But thanks for answering.
|
|
|
|
|
Renato Carvalho wrote: j = test(w);
change with test(&w)
|
|
|
|
|
Modify your function like this,
int test (tpteste ** l)
{
*l = new tpteste[4];
(*l)[0].i = 99;
(*l)[1].i = 98;
(*l)[2].i = 97;
(*l)[3].i = 96;
return 0;
}
|
|
|
|
|
what do you mean exactly by "there's nothing in the pointer 'w'" ?
is it null ?
or you don't see your numbers ?
how do you verify this ?
|
|
|
|
|
Thanks for answering. And that is what happens:
I set a breakpoint on line
j = test(w);
of the function "DoNothing" and verify the value of "w" at the watch window. It shows a value of "0xcccccccc" to it.
Then a step in the function "test". When it executes, the initial value of "l" is "0xcccccccc" too.
Then it executes the command
l = new tpteste[4];
and the value of "l" now is "0x01104eb8".
The assignments
l[0].i = 99;
l[1].i = 98;
l[2].i = 97;
l[3].i = 96;
are executed, and i can see the values at "locals".
The function ends, and returns to the function "DoNothing". The value of "w" is still "0xcccccccc". When i try to see the value of "w[0]" at the watch window, that's what i get: "CXX0030: Error: expression cannot be evaluated".
That's what a mean when i said "there's nothing in the pointer 'w'". I haven't change.
|
|
|
|
|
what about changing this :
int doNothing(void) {
int j = 0;
tpteste w;
j = test(&w);
return 0;
}
|
|
|
|
|
I got lost at what exact point of the changes proposed you are.
The code now looks like this:
typedef struct {
int i;} tpteste;
int test (tpteste ** l)
{
*l = new tpteste[4];
l[0]->i = 99;
l[1]->i = 98;
l[2]->i = 97;
l[3]->i = 96;
return 0;
}
int doNothing(void)
{
int j = 0;
tpteste * w;
j = test(&w);
return 0;
}
When i try to change the code to the one you propodes i get the following error:
"error C2664: 'test' : cannot convert parameter 1 from 'tpteste *' to 'tpteste ** '"
|
|
|
|
|
here is the sample
typedef struct {
int i;
} tpteste;
void test (tpteste** l) {
*l = new tpteste[4];
l[0].i = 99;
l[1].i = 98;
l[2].i = 97;
l[3].i = 96;
}
void doNothing(void) {
tpteste* w;
test(&w);
}
notice the bolde lines in doNothing().
-- modified at 11:35 Wednesday 14th February, 2007
|
|
|
|
|
It shows the same behaviour. The "w" is still the same when it returns.
|
|
|
|
|
i changed my sample since i posted first. please retry
|
|
|
|
|
The code now is:
typedef struct {
int i;
} tpteste;
void test (tpteste** l) {
*l = new tpteste[4];
l[0]->i = 99;
l[1]->i = 98;
l[2]->i = 97;
l[3]->i = 96;
}
void doNothing(void) {
tpteste* w;
test(&w);
}
When it tryes to execute "l[2]->i = 97;" it stops with a adress violation.
|
|
|
|
|
Removing one level of complexity (the struct), take a look at:
void test( int *num )
{
num = new int;
*num = 5;
}
void main( void )
{
int *x = NULL;
test(x);
} You'll notice that when test() returns, x still has a value of NULL . Remember that if we want a function to be able to change something, it must be sent the address (i.e., pass-by-reference) not the value (i.e, pass-by-value). Pointers, too, have addresses and values. Therefore, you must send the address of the pointer.
One of the proper ways to do what you want is:
struct tpteste
{
int i;
};
void test( tpteste **l )
{
tpteste *t = new tpteste[4];
t[0].i = 99;
t[1].i = 98;
t[2].i = 97;
t[3].i = 96;
*l = t;
}
void doNothing( void )
{
tpteste *w = NULL;
test(&w);
}
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Man, it works!
When i pass the adress of the pointer, everything is fine. Not a surprise for you, but a great pleasure for me.
Now i'm gonna follow this way trying to make it work for a array of structures.
Thanks
void test (int **num)
{
*num = new int;
**num = 5;
}
int doNothing (void)
{
int * x = NULL;
test(&x);
return 0;
}
|
|
|
|
|
Man, thanks a lot!
I gonna buy a C++ book today, and i promisse i will (try to) never make a dummy question again.
|
|
|
|