|
Fair enough. I think it's likely OP posted in the wrong group, as neither A, W, or S TL are C libraries.
|
|
|
|
|
The syntax and APIs available depends on your operating system - Windows, OSX, Linux, Net/FreeBSD, Solaris, embedded OSs etc. First, do a search for "Serial port API" and your operating system.
As for how serial communications work, check Wikipedia[^], and pay attention to the hardware signalling and the fact that if you connect two computers, you need a "twisted" cable, and if you connect to a device, you need a "straight" one.
Oh, and this question rightly belong in the "C/C++" discussion forum rather than "ATL/WTL/STL".
|
|
|
|
|
Windows XP, Visual Studio 2008, MFC, Dialog, c++
A button in the main MFC dialog opens a second dialog with options to control the main app. In there is a button that starts disable and after a method is run, is to be enabled. The event handler that initiates that task and enables the button looks like this, so far:
void C_Prog_Control::OnBnClickBtnGetCurrentStates()
{
HWND *button_handle = NULL;
BOOL status = FALSE;
Get_Current_States();
GetDlgItem( IDC_DO_THIS, &button_handle )
status = EnableWindow( button_handle, TRUE );
}
Please forgive, but not ignore, any obvious typos as my work computer is in another room and cannot be connected to the internet. I cannot cut and paste. And now that's worse. I cannot post a message from work and must send the text home and post from there.
I have looked up the GetDlgItem() here: (When I paste in the Microsoft URL it will not display.)
And the EnableWindow function here: (Same for this link).
So the first looks like this on the MS web site:
HWND WINAPI GetDlgItem(
_In_opt_ HWND hDlg,
_In_ int nIDDlgItem
);
and the second looks like this:
BOOL WINAPI EnableWindow(
_In_ HWND hWnd,
_In_ BOOL bEnable
);
The EnableWindow code will not compile. The error is:
… error C2660: ‘CWnd::EnableWindow’ : function does not take 2 arguments.
The compiler does not see, or does not like that I want HWND::EnableWindow rather than CWnd. When I try to use CWnd there are other problems.
Intellisense shows the following signature:
BOOL EnableWindow( BOOL bEnable = 1 )
This differs from the MS page and there is only one signature.
So, given a button with the ID of: IDC_DO_THIS, how can I enable it?
EDIT RESOLVED
While at work, I stopped what I was doing several times and searched for the answer to this several times at work, through the Air Force Firewalls. After giving up there and posting this question from home, I finally found the good idea of searching from home. There in one of the first few pages was a good answer. Tried it, it worked. Just for the record:
void Cvs_2008_get_port_numberDlg::OnBnClickedButton3()
{
CWnd *pfield = GetDlgItem( IDC_BUTTON2 );
pfield->EnableWindow( FALSE );
}
My lesson, try a search at work, but if it does not turn up the answer, search again from home. I presume the Air Force, and all military sites, are attacked so often that they have little choice but to set up things the way they are.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 8-Oct-14 22:20pm.
|
|
|
|
|
When searching MSDN for a particular Windows function you will generally find two links. One of them wil be in the form FunctionName(parameters) , and the other Classname::FunctionName(parameters) . If you are coding pure Win32 then you take the first form, and if you are using MFC you take the second. There are certain functions that do not have MFC equivalents, but that is generally clear from the context.
|
|
|
|
|
I had not noticed that, but will take the time to look for it now. It will probably help to incorporate those into my searches.
Thank you for taking the time to post that.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
Windows 7, Visual Studio 2008, MFC, C++, dialog
Making this short, after failing elsewhere I created a test project. The dialog has one edit box with the default ID of IDC_EDIT1. A button was created and the following code added for that button.
void Cvs_2008_get_port_numberDlg::OnBnClickedButton1()
{
UINT port_number;
BOOL status = FALSE;
int last_error = 0;
port_number = m_box_get_port_number.GetDlgItemInt( IDC_EDIT1, &status );
last_error = GetLastError();
}
Run the code, type in 123 in the edit box, press the button, and port_number gets zero. last_error gets value 1421, Control ID not found.
Some searching indicated that there may be a windows problem: http://www.errorfixes.net/error-1421-windows-7.php[^]
But I find myself skeptical of that.
Do I have a simple error that I can correct? Or is this a deeper problem?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
What is m_box_get_port_number in the above code? I would have expected to see something more like:
BOOL status = TRUE;
port_number = GetDlgItemInt( IDC_EDIT1, &status );
if (status = FALSE)
last_error = GetLastError();
Also, where is the button that this handler refers to: on the dialog or the main window?
|
|
|
|
|
I state up front that I am not experienced with GUIs. My tasks include VS MFS dialogs to control how the app runs and show its performance, but the app is a number cruncher and has no significant user interface. Once started there is no user interaction. The problem is probably a beginner's error so do not hesitate to ask or point out the basics.
This test app is an MFC dialog and has only one dialog. I don't know your intent in differentiating between "dialog or main window." It is only a few steps beyond a just created MFC dialog project.
So far in the test project there is one edit box, one check box, and one button. A right click on the edit box produced a drop down and "Add variable" was selected. The name used was m_box_get_port_number. I added the check for status per your code and it is returned with value 0, false. The error code remains 1421.
The one button has the event handler shown in the OP and runs that code.
Is all that of any use?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
If I understand what you are saying you have an MFC application that is a dialog; that's fairly standard. Within the dialog are a few controls, one of which is an edit box. You then say, "A right click on the edit box produced a drop down and "Add variable" was selected.". That part I don't understand, an edit box is just that, a box that you type text into which allows simple editing. What I would expect to happen would be that you would type something into the edit box, and then click the button. Your button handler would be something like:
void Cvs_2008_get_port_numberDlg::OnBnClickedButton1()
{
UINT port_number;
BOOL status;
int last_error = 0;
port_number = GetDlgItemInt( IDC_EDIT1, &status );
if (status == FALSE)
last_error = GetLastError();
When you prefix your call to GetDlgItemInt with m_box_get_port_number (the edit box variable name) you are trying to find the item IDC_EDIT1 within the edit control. But the edit control does not have a child window with that ID so the call fails.
|
|
|
|
|
Hello Richard,
Quote: You then say, "A right click on the edit box produced a drop down and "Add variable" was selected.". That part I don't understand, an edit box is just that, a box that you type text into which allows simple editing.
My understanding was that to get the value from a control a variable had to be attached to the control. A right click on that control solicits a dialog to add said variable. This method works when I want to get the state of a check box.
However, Now it is clear that this method does not work with the edit control. Following your template, heck, the exact code you wrote, I am able to get the value entered.
I need to take care when examining the results. A zero return value is legitimate only when status is also TRUE. If status is FALSE, then the returned integer is to be regarded as invalid.
OK, I will work with that.
I thank you for the time you spent explaining this.
Edit: Now I realize, or think I do, that my code was trying to reach inside that edit box, which is really a window itself, and try to find another control with that ID of IDC_EDIT1.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
bkelly13 wrote: A right click on that control solicits a dialog I get it now, you were talking about the MFC Class Wizard being used when you develop the application; a long time since I used MFC.
bkelly13 wrote: Now I realize, or think I do, that my code was trying to reach inside that edit box ... Yes, you got it.
Glad you got things working.
|
|
|
|
|
I have the following structure defined inside my DLL and a COM component we developed.
struct ContentStr
{
ContentStr():ptr(NULL), contSize(0), structSize(0), X(0), Y(0){}
const BYTE* ptr;
int contSize;
int structSize;
//output
std::vector<byte> m_v_Data;
int X;
int Y;
private:
ContentStr ( const ContentStr & rhs );
ContentStr & operator= ( const ContentStr & rhs );
};
The COM component invokes a DllExport method in the DLL which accepts the structure as reference and fills its value. It was working fine in VS2008. Recently I ported my code base to VS2013. Now the method throws exception when invoked. When I checked the size of the structure using sizeof operator, I was surprised a bit.
VS 2008:
/*Inside COM*/ sizeof(ContentStr) = 40
/*Inside DLL*/ sizeof(ContentStr) = 40
VS 2013:
/*Inside COM*/ sizeof(ContentStr) = 36
/*Inside DLL*/ sizeof(ContentStr) = 32
I could see that the difference in size is due to the difference in vector size. Searching the internet gave me huge confusion hence I am posting this question on the expert forum. Could someone please explain me why is this difference seen in the sizes and help me find a solution.
Kings
|
|
|
|
|
I don't see how std::vector m_v_Data; will compile; vector is a template class and needs a type to define it.
[edit]
In VS2010 I get 20 for the size of a vector<int> , and in VS2013 I get 16. There must be some other difference in your DLL code that reduces the total by another 4 bytes.
[/edit]
modified 2-Oct-14 3:39am.
|
|
|
|
|
it is vector of BYTE, sorry the code got modified when entered in the editor
Kings
|
|
|
|
|
My apologies also, I think your code got mangled by the HTML tags, you need to use <pre> tags around it (use the code button above the edit window) so it shows up, like:
std::vector<BYTE> m_v_Data;
int X;
int Y;
There is obviously some difference between your application and your DLL. Are they both compiled with the exact same definition for your structure, i.e. using a common header file?
|
|
|
|
|
No they are not, the DLL contains a Util method which is exposed using DLLExport and the COM loads the DLL and creates a method pointer out of it and asks it to fill the data.
Kings
|
|
|
|
|
Well you need to show us the exact code in the application and the DLL, so we can try to figure out what the difference may be.
|
|
|
|
|
I am afraid that could not be done, however if you could point me to the direction where I can start digging through or help me with how you wud have approached this issue it wud be helpful.
Kings
|
|
|
|
|
Sorry, but without seeing your code I have no idea what to suggest, other than some careful reviewing of your code, and use of your debugger.
|
|
|
|
|
It's very bad idea to use the complex types from one DLL to another. Firstly your DLLs can use different "packing size". Secondly these STL types can use own allocators which can be different. Thirdly these STL types can be incompatible due to different realizations of STL.
With best wishes,
Vita
|
|
|
|
|
Could you please suggest me how can I make the packing size as same between COM and the DLL?
Kings
|
|
|
|
|
Check if the VS2008 project is 64bit while the VS2013 one is 32bit.
|
|
|
|
|
No, both the DLL and COM are compiled in VS2013 and are compiled as 32 bit binaries.
Kings
|
|
|
|
|
_SECURE_SCL was enabled in COM amounting to 4 byte increase in size. Removing that solved the issue.
Kings
|
|
|
|
|
I write a function like:
<pre lang="c++">
void func1(char chx[], int y)
{
int wsn = 0;
wsn = *(int *) (&chx);
if (wsn == 0) {
...
}
}
Compiler works well, no warning, no error. But when the code is running, seems it get a wild pointer. the code crashed.
|
|
|
|
|