|
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.
|
|
|
|
|
Should be:
void func1(char chx[], int y)
{
int wsn = 0;
wsn = *(int *)chx;
if (wsn == 0) {
...
}
}
The variable name chx is already a pointer to the array, adding the addressof operator creates a pointer to that pointer.
|
|
|
|
|
Thanks, but I tested, &chx = chx.
|
|
|
|
|
No it doesn't. I have no idea how you tested this but it is not correct. Build the following, step through it with your debugger and you will see that they are different.
int* pAddressOf = (int *) (&chx);
int* pNormal = (int *)(chx);
|
|
|
|
|
I tested in Visual studio IDE.
char s1[] = {'H', 'e', 'l', 'l', 'o'};
printf("%lX,%lX",s1,&s1);
And I get same value for s1 and &s1.
|
|
|
|