|
Hi,
I'm reading documentation about Libraries and how to load, detach them. But I have some concept doubts about.
I have a point in my program where I have to use some functions that should be programmed in a Dll to avoid having that functions in computers where we have not delivered this dll. So when needed, the user should click on a button and search the dll. If the dll is there, then I save the returned name/path of the CFileDialog and set a variable like "m_bLibraryLoadedOK". Afterwards, when the other button is pressed and depending on that bool, I give an error message or use the LoadLibrary function with the saved name/path, use the function I will have in the DLL, and when all is ready... I want to unload the library.
And it now is where I have the doubts.
For example I don't correctly understand the bold part in the following quote: "The Visual C++ compiler supports a syntax that enables you to declare thread-local variables: _declspec(thread). If you use this syntax in a DLL, you will not be able to load the DLL explicitly using LoadLibrary or LoadLibraryEx. If your DLL will be loaded explicitly, you must use the thread local storage functions instead of _declspec(thread)."
The function in the dll is going to need just one variable from my main programm, a pointer/reference to a buffer with the data that have to be written in the PLC. All the other things (if needed) will be local. Should I worry about the quote above? What „key words“ should I look for?
And…
When I load the dll. Is a thread being automatically created? Will the FreeLibrary enough at the end of my function to unload the library? Or will I have to use more things (Like the DLLMain )??
Any tip or Keyword to look for and help me undertand the thema will be apreciated.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Nelek wrote: When I load the dll. Is a thread being automatically created?
No. You can load and call functions in a Dll on the same single main thread of your program. Use of Dlls doesn't require multiple or secondary threads, it's just function calls.
Nelek wrote: Will the FreeLibrary enough at the end of my function to unload the library?
Yes. You can't gaurentee Windows will actually unload it, Windows is lazy but it makes no difference, you can treat it as having been unloaded.
Nelek wrote: Should I worry about the quote above?
No. Not in this case. It only affects variables declared in the Dll with __declspec(thread) where the Dll doesn't have it's own statically linked copy of the C Library, i.e. it isn't already linked with LIBCMT or one of ts variants before you use it.
The explanation of this is that __declspec(thread) inserts an entry in a special data table that is used by the C Library startup routines to setup up Thread Local Storage variables. If the C Library startup doesn't run after your Dll is loaded because it dones't have it's C Library instance then this initialisation never happens and your __declspec(thread) variables are invalid.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
Thank you for the good answer.
The code to read is already working in my program. I just have to code it in the dll and make the loading dinamically. With your answer and two articles I found in the site, I am not so afraid about doing it.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Hi,
I need to remove Cut,Copy Permissions for a folder.Any Suggestions or links would be helpful.
Thanks
Today is a gift, that's why it is called the present.
|
|
|
|
|
This would require removing both read and write permissions from the folder. You can do this by adding that type of ACE to the folder's ACL.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
Thanks for the response.
What I want exactly is to Open the folder and view the contents , and play any files in that folder like Windows Media Player.But I dont want the contents of the folder to be copied or cut.
I did as you said by removing read and write permissions but gave Execute permission and I am getting "Access is Denied" when I try to open the File.
So, I am not sure of the permissions I have to give to folder.Any Suggestions would be helpful.
Thanks in Advance.
Today is a gift, that's why it is called the present.
|
|
|
|
|
hi,
I am a beginner in C++. now I was writing the MFC( dialog based)program for the RFID interfacing. My existing program is upon clicking the start button, it will send the command to the reader and receive the response from it by using serial commnunication within for loop and serial port will disconnect by clicking stop button at the end of 'for' loop. If I click the stop button while program running half way, the program will hang. So, I wanted to implement it that upon clicking start button, my program will start interfacing with reader continuously until I clicked the stop button.So, how can i do it and can support me the sample source code for this similar program?
thanks,
Thinn
This is a part of my existing program
void CTry2Dlg::OnStart()
{
// TODO: Add your control notification handler code here
// ***
char c[40],bcch;
int bcc,ent=0;
int h=0,count=0;
com = new Tserial();
com->connect("COM2", 9600, spEVEN);
char command[15] = {0x02,0x30,0x30,0x52,0x44,0x4D,0x54,0x41,0x41,0x30,0x30,0x30,0x31,0x03};// multi
bcc=com->bcc(command); // obtain BCC
bcch=bcc;
for(int n=0;n<10;n++)
{
GetTime();
for(int i=0;i<15;i++) // send command
{
if(i==14)
{
com->sendChar(bcch);
}
else
{
com->sendChar(command[i]);
}
}
GetDlgItem(IDC_Status)->SetWindowText(command);
GetDlgItem(IDC_Status)->UpdateWindow();
// Sleep(100);
count=0;
do // read response frame
{
h=0;
c[h] = com->getChar();
while(c[h]!=0x03) // to detect ETX of reponse frame
{
h++;
c[h] = com->getChar();
}
// if(c[h]==0x03)
// {
count++;
// }
c[h] = com->getChar(); // BCC
if(c[6]==0x37 && c[7] ==0x32) // check for end of detection
{
ent=1; // endofTx
// if(count>1)
// {
count--;
// }
}
else // more to come ...
{
ent=0;
//cout<<endl<<"uid =="" ";
char="" temp[16];
for(int="" k="8;k<24;k++)
{
temp[k-8]=c[k];
}
CString" appendtext;
getdlgitem(idc_tag)-="">GetWindowText(appendText);
appendText += temp;
appendText += "\r\n";
GetDlgItem(IDC_Tag)->SetWindowText(appendText);
GetDlgItem(IDC_Tag)->UpdateWindow();
}
}while(ent==0); // reading
CString text;
text.Format("%d", count);
GetDlgItem(IDC_Counter)->SetWindowText(text);
GetDlgItem(IDC_Counter)->UpdateWindow();
Sleep(2000);
Clear();//clear the edit boxes
}
}
void CTry2Dlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CTry2Dlg::OnStop()
{
com->disconnect();
CString text=" ";
GetDlgItem(IDC_Counter)->SetWindowText(text);
GetDlgItem(IDC_Counter)->UpdateWindow();
GetDlgItem(IDC_Tag)->SetWindowText(text);
GetDlgItem(IDC_Tag)->UpdateWindow();
GetDlgItem(IDC_Status)->SetWindowText(text);
GetDlgItem(IDC_Status)->UpdateWindow();
}
--
|
|
|
|
|
yah, i got your problem.
but before answering it, i want you to advice that, you donot need to paste the whole code here, because, most of the readers donot prefer read such a big posts. your post should be as simple as possible, and reflecting your actual problem.
and to your question, since, you have defined all your port related code in a single function, i.e. button, your screen (dialog) will not get the focus until the function gets completed.
so the solution is, you have to define this code in a thread, start the thread in the start button and kill it in the stop button.
any more doubts,
you are welcome.
Suggestion to the members:
prefix your main thread subject with [SOLVED] if it is solved.
chandu.
|
|
|
|
|
I'm rather new to this forum,thx for ur advice and i will take note on that. i am new to C++ and i have tried to read through the "instuction to create threading" but i still find it hard to understand. So i greatly appreciate ur help
Thx alot for ur help. =)
--
|
|
|
|
|
Thinn Nwe Han wrote: ...upon clicking start button, my program will start interfacing with reader continuously until I clicked the stop button.
Does the RFID continuously send data to the PC? If not, why waste CPU time asking the RFID for data that does not exist? Instead, let the PC sit idle while waiting on the serial port to notify when data becomes available.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thx for your reply. For my case, the RFID reader does constantly send data back to the PC but i do not know how to write a UI thread to stop my program by clicking stop button.
--
|
|
|
|
|
Thinn Nwe Han wrote: ...i do not know how to write a UI thread to stop my program by clicking stop button.
See here for "shutdown" solutions.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
For the buttons on my dialog based application I need to have an implementation of the OnLButtonDown and OLButtonUp methods so that I know when the mouse is in different 'click' states. Looking at the available control events these aren't availble (only available for the actual dialog).
Is there a way to do this?
TIA,
Andy
|
|
|
|
|
Derive a class from CButton and attach it to the buttons in the dialogs OnInitDialog function (or use DDX_Control to do it in DoDataExchange but you'll have to add the DDX_Control manually outside of AFX_DATA_MAP or use the class wizard to create a member variable for the button using CButton and then move them out of AFX_DATA_MAP and modify the declaration from CButton to CMyButton if you use class wizard to derive CMyButton then class wizard actually recognizes it as a valid variable type I didnt know this), then you can add WM_LBUTTONUP/DOWN handlers to your CMyButton class.
-- modified at 6:42 Monday 15th October, 2007
|
|
|
|
|
Hi, thanks for your reply, I'm having a bad start to the day so could you post a link to an article (or explain) how I can overload the CButton class?
cheers,
|
|
|
|
|
A simple article search for "deriving from cbutton" returned this[^] as the 1st article found
|
|
|
|
|
thanks again for your help (used every word for the search apart from 'deriving'! )
|
|
|
|
|
Use ClassWizard (Ctrl+W). In the Base class combobox, select CButton .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
'class' type redefinition
this is the error i'm getting .. eventhougyh i havent definied it anywhere before in pgm . .. any solution plzzz
|
|
|
|
|
If you put a bit of relevant code, people will be able to help better.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
in the header file which defines your class, put the fillowing aroung your file content :
#if !defined(__A_UNIQUE_MACRO_NAME_FOR_YOUR_FILE__)
#define __A_UNIQUE_MACRO_NAME_FOR_YOUR_FILE__
#endif //__A_UNIQUE_MACRO_NAME_FOR_YOUR_FILE__
|
|
|
|
|
Don't forget to put include guards in your header files:
#ifndef MYFILE_H<br />
#define MYFILE_H<br />
<br />
<br />
#endif
Or you can also use the #pragma directive.
|
|
|
|
|
use #pragma once
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
suganforu wrote: ...eventhougyh i havent definied it anywhere before in pgm.
Obviously you have, or the compiler would not be complaining. Use the #define and #pragma once directives in your class definition file.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can anyone suggest any book for working VC++ with Flash 8
Thanks in advance
sai
|
|
|
|