Solved

A DLL dummy asks a question

Posted on 2000-02-18
6
156 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 100 total points
ID: 2537390
And removing 'var' in the declaration?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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