[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

Unable to send Parameters to Draw method in kodak imaging OCX

I'm using the Kodak Imaging OCX
& trying to draw an image in it in VB.
When I write:
TestOcxImage.Draw leftPos, TopPos, 100, 100
it's working.

But when I write
TestOcxImage.Draw leftPos, TopPos, rightPos, bottomPos
The debugger writes: "Invalid values with width or height parameters".

I tried to define the parameters as integer, variant, long. but to no avail.

anyone has a solution to this strange behavior ?
0
MagicianH
Asked:
MagicianH
  • 8
  • 7
1 Solution
 
shamstarCommented:
What annotation type are you using?
0
 
MagicianHAuthor Commented:
TestOcxImage.AnnotationType = 3 'rectangle stamp
0
 
shamstarCommented:
how have you assigned values to rightPos and bottomPos, ideally, could you give the line of code you set the value for them on?
From the error message, I would just assume that you are using the wrong data type, maybe you have some speach marks somewhere where they shouldnt be?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
MagicianHAuthor Commented:
I'm copying to you the part of code that doesn't work
(with me trying to define the variables & without...)

    leftPos = 50
    TopPos = 50
'    Dim rightPos As Long
'    Dim bottomPos As Long
    rightPos = 100
    bottomPos = 100
    'if you will comment this line, the next line will work, amazing - no ?
    TestOcxImage.Draw leftPos, TopPos, rightPos, bottomPos
'    TestOcxImage.Draw leftPos, TopPos, 100, 100
0
 
shamstarCommented:
Huummm... cant see anything obviously wrong there.  You said you have already tried declaring the variables as long (which is what they are supposed to be) but this didnt work.

The comment above the TestOcx line is interesting, do you actually mean that with that comment line there the code works fine but once you remove it you get the error (or another error) ?? Very strange.

Have you treid to see if there is an updated version of the control on the Kodak site, or even information bout this specific problem in their forums or FAQ's ??
0
 
MagicianHAuthor Commented:
I didn't see any information in the KODAK site or any way to download their updated version...

I'll try to send their support an email.
0
 
shamstarCommented:
Yep.. that would be the next best thing to do :-)
Let me know what they say.
0
 
MagicianHAuthor Commented:
I found that my ActiveX expects a constant.
is there a way to send it a variable ?
0
 
MagicianHAuthor Commented:
I found out what I should do:

    Const rightPos As Variant = 100
    Const bottomPos As Variant = 100

that problem is that I want to send the ActiveX *variables*, not constants - is there a way to do it ?
0
 
shamstarCommented:
The only way around the const problem that I can think of is by using pointers.  Since VB is anaged fairly tightly, you might not have come across pointers unless you've used it in another language.  But dont worry, its not really that difficult to do, and there isnt too much either.

I wont go into too much detail with explaining pointers since there are many places on the web that do that already.  If you do want more info on them then just ask.

Heres what you need to do:

1) Declare this function (copy and paste):
-------------------------------------------------
Public Declare Sub CopyMemoryWrite Lib "kernel32" Alias _
    "RtlMoveMemory" (Byval Destination As long, Source As Any, _
    ByVal Length As Long)
-------------------------------------------------

2) Declare a variable that will be used to point to your constant called rightPos for example.  Do this using the next line:
------------------------------------------------
Dim lngRightPointer As Long
------------------------------------------------

3) Set the pointer variable above to point to the rightPos constant:
------------------------------------------------
lngRightPointer = VarPtr(rightPos)
------------------------------------------------


4) Now to change the value of the rightPos constant:
------------------------------------------------
dim lngTemp as long
lngTemp = 10
CopyMemoryWrite lngRightPointer,lngTemp,2
------------------------------------------------

Thats all there is to it.  The rest of your code will still be the same, and you will still pass the rightPos and leftPos constants into the Draw function.  The only difference is that you can now change the value of the constant any number of times you like within your code by using the code shown in step 4.

Hopefully I've explained and given you enough code to get this working withing a few minutes.  I got a few of those lines of code from an article I read ages ago, but dont think its on the web anymore otherwise I would have given you that to read as well (its not much good on its own though).

Goodluck! :-)

0
 
MagicianHAuthor Commented:
Your solution is great, BUT...

it works only if I declare the rightPos with Dim, but when I declare it as constant,
I suppose windows blocks the operation of this method & it doesn't work.

other suggestions ?
0
 
MagicianHAuthor Commented:
Shauli from the VB forum gave me this amazing solution:

Const rightPos As Variant = 100
Const bottomPos As Variant = 100
Dim MyrightPos As Variant
Dim MybottomPos As Variant

' set to any number I want

MyrightPos = 321
MybottomPos = 432
TestImage.draw leftPos, topPos, rightPos + (MyrightPos - rightPos), bottomPos  + MybottomPos - bottomPos)
0
 
shamstarCommented:
Well, I've tried a few things and Ive got no idea why the pointer thing doesnt work even with a constant.  Let me know if you still want me to have try a bit more to get that to work, otherwise you can use the above method, with a minor modificatoin... i.e. set the constants to be zero, that way it might make things easier for you in the code since you wont have to look at the numbers and do the subtractions.
0
 
MagicianHAuthor Commented:
I think that the windows "knows" that a variable is a contant & doesn't let the procedure to work.

Anyway, Since I have solution to my problem, you don't have to worry about it anymore :)
0
 
shamstarCommented:
The problem in my suggestion was that the VarPtr does not return the correct address of constants, only of variables - so without the correct address the change isnt possible.
But since you're sorted now, you need to get this question closed, you can do this by making a post to the Community Support section of the site, provide a link to this question and ask them to refund your points and PAQ this question.
0
 
moduloCommented:
PAQed, with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now