PDA

View Full Version : Getting DLL to work



SGW
08-17-2009, 10:06 AM
Hi,

I have a DLL written by a friend that I am having difficulty getting to work in AMS 7.5. (I have gotten it to work in another program with similar function calling features and requirements, so it does work).

It's a Win 32 unmanaged code DLL written in C++ that can send SMTP mail.

Its only function is "SendEmailMessage" and all parameters are strings:
sHost, sUserName, sPassword, sPort, sFrom, sTo, sSubject, sFile, sBody. Items that are not specified can be represneted by "". If successful an empty string is returned, if unsuccessful, an error string is returned (the developer has said that it should work OK without a return/result specified).

I have tried several variations like the following, without success:


sHost = "xxxxserver.net"
sUserName = "admin@xxxx.com"
sPassword = "yyyyy"
sPort = "25"
sFrom = "admin@gggg.com"
sTo = "info@gggg.com"
sSubject = "xxRegistration"
sFile = ""
sBody = ""
result = DLL.CallFunction("C:\\Users\\xxxx\\Documents\\AutoPlay Media Studio 7.0\\Projects\\AMS081409\\sendemail.dll", "SendEmailMessage", sHost, sUserName, sPassword, sPort, sFrom, sTo, sSubject, sFile, sBody, DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);
Dialog.Message("Notice", "Your message here.", result);

I've tried this with no "result" just by calling the function. I've tried this with all types of returns (string, long, etc.), both calling conventions, with and without quotes on the variables, plugging the actual variable values in, etc.

Nothing has worked, yet in the other program,it works, sending SMTP mail every time. So, my LUA syntax must be wrong somewhere.

Any suggestions, help would be appreciated.

Kind Regards,

SGW

Worm
08-17-2009, 10:15 AM
make sure you are sending strings into the DLL with quotes around them. That's usually where I mess up sending parameters to a DLL

SGW
08-17-2009, 10:37 AM
Hi worm,

Thanks for your suggestions. I went back, entered the values in quotes for each parameter, double-checked everything, including spelling. I took out the return ("result =") and dialog message, relocated the dll to desktop and re-configured the path, but still can't get this to work.

A real challenge...

Kind Regards,

SGW

Worm
08-17-2009, 11:09 AM
liek this?


function QuoteMe(sIn)
return "\""..sIn.."\""
end

result = DLL.CallFunction("C:\\Users\\xxxx\\Documents\\AutoPlay Media Studio 7.0\\Projects\\AMS081409\\sendemail.dll", "SendEmailMessage", QuoteMe(sHost), QuoteMe(sUserName), QuoteMe(sPassword), QuoteMe(sPort), QuoteMe(sFrom), QuoteMe(sTo), QuoteMe(sSubject), QuoteMe(sFile), QuoteMe(sBody), DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);


You can use Appication.GetLastError too to see what may be happenning.

SGW
08-17-2009, 11:27 AM
Thanks, Worm.

Tried that, but still can't get it to work. (But a useful function to have!)

Kind Regards,

SGW

nrgyzer
08-17-2009, 11:45 AM
When you use multiple arguments/parameters you shouldn't use blanks between them...


result = DLL.CallFunction("C:\\Users\\xxxx\\Documents\\AutoPlay Media Studio 7.0\\Projects\\AMS081409\\sendemail.dll", "SendEmailMessage", "localhost, username, password, port, from, to, subject, file, body", DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL); is different to


result = DLL.CallFunction("C:\\Users\\xxxx\\Documents\\AutoPlay Media Studio 7.0\\Projects\\AMS081409\\sendemail.dll", "SendEmailMessage", "localhost,username,password,port,from,to,subject,f ile,body", DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);

correct form is


"localhost,username,password,port,from,to,subject,f ile,body"

Try the following code:


result = DLL.CallFunction("C:\\Users\\xxxx\\Documents\\AutoPlay Media Studio 7.0\\Projects\\AMS081409\\sendemail.dll", "SendEmailMessage", "\""..sHost.."\",\""..sUserName.."\",\""..sPassword.."\",\""..sPort.."\",\""..sFrom.."\",\""..sTo.."\",\""..sSubject.."\",\""..sFile.."\",\""..sBody.."\"", DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);

or...


result = DLL.CallFunction("C:\\Users\\xxxx\\Documents\\AutoPlay Media Studio 7.0\\Projects\\AMS081409\\sendemail.dll", "SendEmailMessage", "'"..sHost.."','"..sUserName.."','"..sPassword.."','"..sPort.."','"..sFrom.."','"..sTo.."','"..sSubject.."','"..sFile.."','"..sBody.."'", DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);

but... make sure, that you have the correct data type... for example... -> we call sPort as a string and not as an integer value...

SGW
08-17-2009, 01:40 PM
Hi nrgyzer,

Thanks for these suggestions. Tried them all, plus every variation that I can think of.

Can't get it to work.

In the other software, the DLL has to be loaded first by a LoadDLL function. Then, after loading, the DLL's functions can be called (using a JavaScript syntax very similar to LUA in AMS). Am I missing the need in AMS to "load" the DLL before calling the function.

This DLL was written to be very simple: it only has one function call, and the parameters necessary to send SMTP mail. It was written in C++ and compiled in a Borland Delphi compiler. All parameters are strings, and a return is optional and unnecessary (return is also is a string).

I can't think of anything else to try.

Kind regards,

SGW

nrgyzer
08-17-2009, 02:48 PM
You don't need such LoadDLL-function ;)...

Does the applications crashs when you call the DLL? -> if yes... do you use the correct ReturnType and CallConvention?

Suggestion: remove every functions from the DLL, add a simply return of one argument/parameter, recompile it and try to call the dll... if the dll doesn't work, remove some arguments/parameters and try again... until it works

SGW
08-17-2009, 03:29 PM
Hi nrgyzer,

No, it doesn't crash or show any script error messages. (And it works in the other software when loaded and called using a form of JavaScript.)

A developer friend created this DLL for me several months ago, so I did not compile it. I can't re-compile it, especially since this was developed in Delphi and compiled with a Borland compiler. (I had first tried to write my own DLL in C++ using VisualStudio 2008 C++ Express, but no success: it was far beyond my ability.)

It should work in AMS, if I can get the correct function calling syntax. In the JavaScript function call, the other software specifies if there is a return or not, and prefaces each parameter with its type (for example: string, sUserName). However, in this DLL, all parameters are strings, even port 25 ("25").

My friend told me that although it will return nothing if it works OK, and returns an error message (string) if it fails, it is not necessary to call the function using a return. But, I have tried every way: no return, return, return as LONG, return as STRING, even integer. Will not work.

So, I can keep trying, but this DLL may not work in AMS.

Kind Regards,

SGW

reteset
08-18-2009, 12:18 AM
This code should work
if it does not work , then you should check parameters order



sHost = "xxxxserver.net"
sUserName = "admin@xxxx.com"
sPassword = "yyyyy"
sPort = "25"
sFrom = "admin@gggg.com"
sTo = "info@gggg.com"
sSubject = "xxRegistration"
sFile = ""
sBody = ""
Vars = "\""..sHost.."\",\""..sUserName.."\",\""..sPassword.."\",\""..sPort.."\",\""..sFrom.."\",\""..sTo.."\",\""..sSubject.."\",\""..sFile.."\",\""..sBody.."\""
result = DLL.CallFunction("DllPath", "Myfunction",Vars,DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);

Delphi Dlls can only accept string type arguments from non-delphi envirounments
and it is PChar

Worm
08-18-2009, 07:03 AM
Plus, put this after your DLL call. It may help shed some light on the underlying issue.



e = Application.GetLastError()
if e~= 0 then
Dialog.Message("Error", _tblErrorMessages[e])
end

SGW
08-18-2009, 07:23 AM
Hi reteset and worm,

Thanks very much for your continued help.

reteset: I carefully placed the suggested code into the button.

worm: I added the error check after the function call. It states:

"Failed to load the specified DLL."

I moved the DLL from its location in the AMS project folder to the desktop. Still get the error message that it is failing to load.

Can't figure this out. Checked and double-checked the path. It is correct.

When I load this DLL using the other software, it loads and works OK. So, I am not sure why it is failing to load in this AMS project.

(reteset: As an alternative to using this DLL, I tried the SMTP plugin, since this would be another excellent solution to being able to send SMTP mail. I have a Vista 64 bit home premium OS, and the plugin-latest version-would not work: I kept getting program crashes. I used gmail, since I have a gmail address, plus I tried 2 other mail accounts. All crashed the program in preview and in build.
I also tested using Telnet client. The gmail SMTP server link worked in telnet only for port 587, but not for port 465. 465 in telnet just kept trying to connect, but after several minutes, gave up. 587 connected quickly. I'm not familiar with using telnet, so I'm not sure what is happening, or even if the result for 587 was a good result. Bottom line: can't get the plugin to work in my Vista 64 OS. If I can help more with error codes, etc. please let me know.)

Kind Regards,

SGW

SGW
08-18-2009, 08:20 AM
Hi,

OK. I changed the DLL location ("AutoPlay\\Docs\\sendemail.dll"), and it loaded and worked! :)

Thanks again for all of your help!

Kind Regards,

SGW