Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

A DLL dummy asks a question

Posted on 2000-02-18
6
Medium Priority
?
163 Views
Last Modified: 2010-04-04
Hello Experts;

Trying to use a simple DLL function (written in C) that sets a voltage through a serial port.

The text from the documentation file reads:

=====================================================
Name: SetVoltage
Description: Sets the Voltage.
Entry Parameters: dV is the Value required. nMaxV is the known maximum for the voltage unit, which is planned  to be 2000
Returns:          0 = failed
                  1 = success
                  -1 = range error
                  -2 = no COM1 available

int SetVoltage ( double dV, int nMaxV );

Example:
         int nSuccess = SetVoltage ( 750.0, 2000 );

=====================================================

I've put the following into an application:

///////////////////////////////////
{$R *.DFM}

Function SetVoltage(var dV:double; nMaxV:integer):integer; stdcall; external 'THE.dll';

procedure TForm1.Button1Click(Sender: TObject);
var
  temp, nMaxV : integer;
  dV : double;
begin
  dV := 750.0;
  nMaxV := 2000;
  Temp := SetVoltage(dV, nMaxV);
  Label.Caption := inttostr(temp);
end;
///////////////////////////////////

I can't seem to make this function return anything other than -1 for range error.   I believe this should work but I'm getting nowhere.  I think it's time to ask people who are smarter than me...

Thanks in advance...

Paul
0
Comment
Question by:prstein
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 2537372
Try cdecl instead of stdcall.
0
 
LVL 1

Author Comment

by:prstein
ID: 2537379
Hello Epsylon;

Thanks, but tried that.  Gives an access violation and brings up that ugly CPU window.

Paul
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 400 total points
ID: 2537390
And removing 'var' in the declaration?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:prstein
ID: 2537416
Tried that, and it more-or-less worked.  Now it returns 0 for "failed."

If you can tell me that the reason for this is either with the device or the dll and NOT my code, I'll gladly give you the points.

And if it's not too much, why would removing "var" from the declaration do the trick?

Paul
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2537456
>Tried that, and it more-or-less worked.  Now it returns 0 for "failed."

Does the dll receive the correct values dV and nMaxV values? Did you use stdcall or cdecl?

>If you can tell me that the reason for this is either with the device or the dll and NOT my code, .......

ehhh I can see the device nor the dll and except for the 'var' and 'cdecl' stuff I can't see any other flaw.

>And if it's not too much, why would removing "var" from the declaration do the trick?

Var means that the parameter is passed by reference (pointer) and not as a value.
0
 
LVL 1

Author Comment

by:prstein
ID: 2537501
> Does the dll receive the correct values dV and nMaxV values?

As far as I know.  How could it not?

> Did you use stdcall or cdecl?

It worked with stdcall.  Going without "var" and with "cdecl" crashed Delphi spectacularly.

> Var means that the parameter is passed by reference (pointer) and not as a value.

Thank you!

I think at this point I can safely go to the generator of the code and complain to him.  Thanks much and the points are yours.

Paul
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question