Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Sep 2005
    Posts
    87

    Getting DLL to work

    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:

    Code:
    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

  2. #2
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    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

  3. #3
    Join Date
    Sep 2005
    Posts
    87
    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

  4. #4
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    liek this?
    Code:
    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.

  5. #5
    Join Date
    Sep 2005
    Posts
    87
    Thanks, Worm.

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

    Kind Regards,

    SGW

  6. #6
    Join Date
    Feb 2005
    Location
    Germany
    Posts
    135
    When you use multiple arguments/parameters you shouldn't use blanks between them...

    result = DLL.CallFunction("C:\\Users\\xxxx\\Documents\\Auto Play 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\\Auto Play 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);
    correct form is

    "localhost,username,password,port,from,to,subject, file,body"
    Try the following code:

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

    result = DLL.CallFunction("C:\\Users\\xxxx\\Documents\\Auto Play Media Studio 7.0\\Projects\\AMS081409\\sendemail.dll", "SendEmailMessage", "'"..sHost.."','"..sUserName.."','"..sPassword.."' ,'"..sPort.."','"..sFrom.."','"..sTo.."','"..sSubj ect.."','"..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...
    Last edited by nrgyzer; 08-17-2009 at 10:55 AM. Reason: bad english :-D

  7. #7
    Join Date
    Sep 2005
    Posts
    87
    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

  8. #8
    Join Date
    Feb 2005
    Location
    Germany
    Posts
    135
    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
    Last edited by nrgyzer; 08-17-2009 at 01:53 PM.

  9. #9
    Join Date
    Sep 2005
    Posts
    87
    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

  10. #10
    Join Date
    May 2006
    Posts
    1,443
    This code should work
    if it does not work , then you should check parameters order


    Code:
    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

  11. #11
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Plus, put this after your DLL call. It may help shed some light on the underlying issue.

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

  12. #12
    Join Date
    Sep 2005
    Posts
    87
    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

  13. #13
    Join Date
    Sep 2005
    Posts
    87
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts