Cannot send info from dll to exe with WM_COPYDATA - delphi

I am trying to send a record from one dll to one exe.
The dll is an Outlook add-in I wrote, the exe is my main application.
I used this example to succesfully send a record from exe to exe, but when I try to do the same from dll to exe it doesn't work.
Note: please open the link and there you find the code I am using. That code is for an EXE sender application and a EXE sender application. This works.
If I put the sender code inside a dll the example doesn't work anymore.
Could you suggest a solution?

Assuming that you can make it work with a string (which remains to be seen), you could simply serialize your record to a string (CSV, possibly using a weird delimiter like ~), send as a string (PAnsiChar or PWideChar), then de-serialze back into the record at the other end. This isn't as elegant as what you want, but absolutely, positively, will work.

Related

How can i get the Handle of a Form that are using my DLL?

I got a Form that are using a DLL.
Have a way to get the Handle of the Form through the DLL?
Something like this:
SetWindowText(HandleOfTheForm, 'This Program is using my DLL');
Sorry by the grammar mistakes.
There is no way for the DLL to automatically discover the Form window without having some prior knowledge about it. Either the Form itself needs to tell the DLL which HWND to use, such as by a function that the DLL exports, or by giving the Form a known/predictable class name and/or window title that the DLL can look for, such as by using FindWindow() or EnumWindows().
A better option is to write the DLL to expose a callback that the Form can assign a handler to, then have the DLL call it when needed and let the Form decide what to do when called. That way, the DLL does not need to know anything about the Form at all.

Lua - how to write string to editor or browser window

I have an app written in Lua with wxLua. While this app is running, I want to be able to send a (large) string to an external program so the user can view the string, search it, etc.
This external program can be notepad, notepad++, etc, or even a browser window, as long as the user can view and search the text.
I can open open an editor using
local handle = io.popen("notepad", "w") -- for example
but then
handle:write (myString)
doesn't show anything in the editor. And notepad++ doesn't even open a new window if I already have it running.
I can launch a browser using
wx.wxLaunchDefaultBrowser ("http://stackoverflow.com")
but I don't know how to pass the (100-200kb) string to the browser window.
Any help is very much appreciated, thank you!
Stomp
Print out text or HTML file and then open it in browser with wx.wxLaunchDefaultBrowser ("file://path/to/file") or use os.execute to run external editor with same file as argument.
See Oleg's post for the best solution, IMO.
Another solution would be to place your text on the clipboard, so the user could paste it wherever they like.
As for injecting text into apps that are already open, that's non-trivial and beyond the scope of what you can do with wxLua. You'd need to use COM interfaces or traverse the apps' control structures using Win32 API calls or something equally hairy and often app-specific.

How to put configuration information inside the executable?

If we want to store critical information, like passwords and server addresses, inside the executable file generated by the Delphi compiler, how can we do that, without knowing the final executable size and binary structure, like at the end of the file for example?
Side note:
The text to be stored is already encrypted; and in some computers the windows don't give access to write in the registry, specially when the user is not administrator, and there are hacks to monitor registry changes and the smart user can find the new windows registry entry.
Comment
Why this question was down voted? This is achievable! Doesn't meter if not interesting for most people.
I think about the bios and other firmware upgradeable, like satelite tv signal decoders that update themselves. How is that possible?
You can use an .rc file to put your data into a custom resource inside the final .exe file. You can then access that resource at run-time, such as with a TResourceStream, and decrypt and use its content as needed. However, you cannot write new data into the resource while the .exe is running, as the file is locked by the OS. If you need to write new settings, and do not have write access to the Registry, you will have to use a separate file instead. Windows has special folders set aside that users have write access to within their user profiles.
Create a string table resource is one way.
Create a text file. say secretstuff.rc (has to have .rc extension)
with something like this in it.
STRINGTABLE
{
1,"This is my encrypted password in say Base64"
}
Compile it to a .res file with BRCC32.
Include it in the relevant code with a compiler directive
{$R secretstuff.res}
After that you access with TResourceStream.
If you want to manage it a bit better might be wise to stuff them in a dll instead of an exe, then you can update things by delivering a new version of the dll.
There's an example with a it more detail, another purpose but same principle here

How to extract dll from the resource

my application uses Bass.dll and i added it to the resource. I wanted it to be extracted before the application starts it chrash. how to void it?
XBasic3000, I think your problem is wich maybe you are using a external declaration like this
function Foo: integer; stdcall; external 'bass.dll';
so the OS cannot resolve the address of the function in the dll.
instead you must use the LoadLibrary() and GetProcAddress() functions after extracting the DLL, in this way you can avoid crashing by checking for the existance of the DLL.
I think that the solution to your problem is described by RPUZ or Chris Thornton (both up-voted). If extracting files to the hard drive causes you trouble, you should know that it is possible to load the DLL directly from memory instead.
Zarko Gajic explains at delphi.about.com.
If you extract the DLL, where do you put it? Your app isn't a setup app (setup.exe) which would have special privleges, so it cannot write to \windows\system32 or even \program files\yourapp under Vista/Windows7. Attempting to put it into the program directory will result in it being located elsewhere, via the VirtualStore. So you must verify FileExists('bass.dll') prior to attempting LoadLibrary().

How to use Delphi to get email message text from Thunderbird

What I do now with Outlook:
I receive email orders for products. I select a single or multiple emails in Outlook (a single order can have multiple emails associated with it) and then switch to my Delphi coded OrderManager program and click "Import". It uses Outlook's COM automation interface to read the text of each message, parses and processes each one.
The question is, can I do this using Thunderbird instead? Does Thunderbird have a COM interface? I must be googling the wrong keywords because I haven't found anything yet.
Btw, I do have a version of my OrderManager that just reads the emails directly from my email server using Indy, but for several reasons I'd like to try to read them from Firefox.
Any suggestions, links to docs, or code samples will be greatly appreciated!
Check this link out.
You could write a C or C++ wrapper around XPCOM and then use that wrapper within Delphi.
There is also an open source XPCOM wrapper written in Delphi. You might want to check that out as well. Thanks Stijn for pointing that out.
Hope it helps.
You could also parse Thunderbird's mailbox files yourself.
From %APPDATA%\Thunderbird\profiles.ini, read where the profile folder is located (if there's more than one profile, look through sections Profile0..Profilen for the one that has the value Default=1)
Each subfolder of the Mail and/or ImapMail subfolders of the profile folder represents an account (Mail contains POP accounts, ImapMail contains IMAP accounts);
Look through all files whose names don't end with .dat or .msf, and whose contents start with 'From ' (F, r, o, m, and a space). Those are the mailbox files.
Every line that starts with 'FromĀ ' indicates a new message. Use the X-Mozilla-Status header to figure out whether the message is still valid, or whether it's been marked for deletion. (You can use the CDO.Message COM object to parse the message for you, if you want).
You should recurse for each subfolder ending on '.sbd', since that will contain that mailbox's subfolders (E.g. Inbox.sbd will contain the mail folders under the Inbox).
Be wary of file locking issues, however.

Resources