Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

two simple questions

Posted on 1999-07-23
12
Medium Priority
?
275 Views
Last Modified: 2013-12-03
1:There is a globle variable "A" in a .DLL ;
In my .EXE, I also have a int variable "B" that have a meaningful content.Now,I load the .dll and I want to put the B's content into A;like B=A;How can I achieve?
If I write B=A in my .EXE,there will be unsolved error for "A".
How can I transport variable content between .dll and .exe?

2.Is .DEF necesaary for a .DLL which I want to export a few functions from .Are there other ways?


3.I have get a handle of a window and I want to get the threadID of it.I use GetWindowThreadProcessId() but I dont know what should be put in the second param.


Really hope somebody expert can help me.
Thanks.

0
Comment
Question by:SFS
[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
  • 6
  • 4
  • 2
12 Comments
 

Author Comment

by:SFS
ID: 1403633
Edited text of question.
0
 

Author Comment

by:SFS
ID: 1403634
Adjusted points to 150
0
 
LVL 1

Accepted Solution

by:
rocket96 earned 600 total points
ID: 1403635
1. Use shared memory. Search MSDN for "shared memory". I have soure lying around, but I'll have to dig around for it. Lemme know if you need it.

2. Use __declspec( dllexport ) to export functions.

3. If you have a DWORD as the thread ID, pass a pointer to it:

DWORD threadID;
GetWindowThreadProcessID( hWnd, &threadID );
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:SFS
ID: 1403636
Thank you,rocket96.
1.The so called "share memory" is meant to be shared between the .exe that load the .dll and the .dll ,right?
would you please give me a simple but concrete example ,just like make A=B(A in .dll and B in .exe).

BTW:I'm very urgent for the answer.I 'm writing a critical and very important homework and I will send in it tomorrow that is deadline!:)

2.I add the __declspec( dllexport) before my function FUNC which  in my .dll and I compile it successfully.Then,in the .exe ,I use LoadLibrary() first,it succeed. When I use Loadprocaddress() in my .exe,It return NULL,wrong! Should I add something else to my .exe? I import it correctly if I use a .DEF file to export that function.  

3.Thank you,I succeed.
But I'm so curious that ,originally,I use these words to do but failed.
LPDWORD pthreadid;
GetWindowThreadProcessId(hwndnote,*pthreadid);

Now I change as you said, but what the difference?



0
 
LVL 1

Expert Comment

by:rocket96
ID: 1403637
1. Sorry, didn't read your question properly. If you want B=A where B is in the DLL and A is in the exe, then just have a function which the exe can call into the DLL to set B. I can't explain more becuase its a homework question and we're not allowed to answer homework questions.

2. When you use __declspec( dllexport ), you should get an import library which your exe links against. There's no need to call LoadProcAddress() unless you don't have an import library.

3. You declared a pointer which was not allocated. And then you dereferenced an unallocated pointer. Thats not legal.
0
 

Expert Comment

by:Babyworship
ID: 1403638
1:OK,that's enough,thanks
So,you misunderstand and what is "shared memory",when should I use? would you tell me?(This is not homework question:)


2.So,if I want to use LoadProcAddress() to import a function that in a .dll.I must write a .DEF?

3.Thanks.
0
 

Expert Comment

by:Babyworship
ID: 1403639
BTW:I have send in my homework as I said last time.
I fail and I don't know how to make A=B.How I declare B(in .dll) in .exe?

0
 

Author Comment

by:SFS
ID: 1403640
Woo,what's the problem why Babyworship say that?

0
 
LVL 1

Expert Comment

by:rocket96
ID: 1403641
If B is in a DLL, and A is in an exe, and you want to do:
1. A = B
Export a function in your dll, say GetB(), which returns the value of B. Then your exe code can have:
A = GetB();
Where GetB() is exported from the dll.

2. B = A
This is a little trickier. You can use "shared memory" or memory mapped files, but these techniques are more advanced. Alternatively, you can export a function in your DLL called SetB( argument ); and call it in your EXE like this:

SetB( A );

To use LoadProcAddress, you don't need a def. You should be able to do it with __declspec( dllexport ). I was able to get this to work...
0
 

Author Comment

by:SFS
ID: 1403642
1...>>You can use "shared memory" or memory mapped files

I think those two tech are all used to share memory between different processes.But a .dll is in the same process of the .exe.Why you said  I can make use of them to make B=A?(B in .dll,A in .exe)?

2...I still failed even I add the __declspec(dllexport);But originally I succeed if I add a .def,here is my code.

In .exe:

hinstDLL = LoadLibrary((LPCTSTR) "xx.dll");  
hp = (HOOKPROC)GetProcAddress(hinstDLL, "Proc");

The "hp" return NULL,if I compile .dll with a .def

LIBRARY xx
EXPORTS
Proc

It is ok ...

In .dll:
__declspec(dllexport) LRESULT CALLBACK Proc(int nCode, WPARAM  wParam, LPARAM  lParam );
//declaration,I add what you said.
   
LRESULT CALLBACK Proc(int nCode, WPARAM  wParam,  
                                LPARAM  lParam  
                            )
{
                  
.........................................

}
//implementation


Could you find some things wrong?
Thanks...
0
 
LVL 1

Expert Comment

by:rocket96
ID: 1403643
1. If you use memory mapped files or shared memory, then you can say B=A or A=B with either variables in an exe or a dll.

2. If the return value from GetProcAddress() is NULL, use GetLastError() to check the last error.
0
 

Author Comment

by:SFS
ID: 1403644
2.I use the GetLastError() and It return 126,it's  ERROR_MOD_NOT_FOUND :
The specified module could not be found.

The loadlibrary is ok,why?

 
 
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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