|
I have a form (name MyForm), where I want to know when the Arrow keys pressed
so I made this function but its not working for the arrow keys.
Its working great for all the others (shift, alt, caplock.....)
dont know what to do please help
in the constructor:
this->add_KeyDown(new KeyEventHandler(this, &MyForm::KeyDown));
the function:
void MyForm::KeyDown(Object *sender, KeyEventArgs *e)
{
switch(e->KeyCode)
{
case Keys::Down:
MessageBox::Show("Key Down was pressed");
s->Down(picGame->Handle);
}
}
I tried to step with the debugger, nothing happens when I press arrow keys
Its not getting in to the function
for all other keys it does.
|
|
|
|
|
Hai,
I just copied your code and its works!!!!
Sometimes the focus is not on your Form .
|
|
|
|
|
Youre right.
I tried it with an empty form and it worked.
I have on my form only a picturebox and a button, how can I keep the forms focus always.
I never need the focus on the other controls.
thanks.
|
|
|
|
|
hai,
Sorry i dont know how it solve!!!
Some where i found to override the ProcessmdKey method
but i didn't get too much ideas
If u solve the problem plz post it
by
ANish
|
|
|
|
|
Thanks
I will post if there will be any soloution.
Yuval
|
|
|
|
|
Can anyone help me?
I am getting this error..
h:\169\program 3\ManageData.cpp(62): error C2782: 'int ManageData::searchArray(T [],int,T)' : template parameter 'T' is ambiguous
with this call statement..
index = searchArray(studentArr, numStudents, entry );
that calls this function...
template<typename T><br />
int searchArray(T arr[], int size, T target)
grrrrrr, I can't get rid of this stupid error!
|
|
|
|
|
For about a week now i have been reading and reading but still can not make any sense about strings in C++ .Net.
Problem 1 is comparing strings, for example:
String* Str1 = "HELLO";
if (Str1 == "HELLO") // Also Tried using Compareto
{
TextBox1 -> Text = "Same";
Else
TextBox1 -> Text = "Not The Same"";
}
I have even put in breaks just to make sure that the strings are the same - which they are.
Problem 2, does left, right, mid still exsist?
Thanks,
Dave
|
|
|
|
|
You are comparing two objects not strings! This will work:
String* Str1 = S"Hello";
if (Str1->CompareTo(S"Hello") == 0)
...
However, the following will seem to work but you are actually comparing the same object to itself:
String* Str1 = S"Hello";
if (Str1 == S"Hello")
...
Str1 is actually pointing to S"Hello". S"Hello" really a String object.
S"Hello" actually means new String("Hello");
Thus S"Hello" or (Str1) does not equal the literal string "Hello" (without the S prefix).
Also, use the String object's method "SubString", for Left, Right and Mid.
|
|
|
|
|
Hai,
You can comapre the Strings using the static Compare method in the String class
ie
String* str=S"HELLO";
if(String::Compare(str,"HELLO")==0) //ie Same
{
TextBox1 -> Text = "Same";
}
else
{
TextBox1 -> Text = "Not The Same"";
}
SubString function done all the left, right and mid functionalities
by
Anish
|
|
|
|
|
One more little thought to add to the above:
You can not change a String object. Replace
only deletes the old and creates a new object.
Once created the String is fixed. So -- if in
a loop changing a sting; be careful of using
String.
WedgeSoft
|
|
|
|
|
Hey guys, I'm trying to get a callback function to work from my unmanaged C++ dll. Everytime I run my program I get System.NullReferenceException saying "Object reference not set to an instance of an object." in mscorlib. This error is thrown when the runtime tries to execute the callback function in my unmanaged C++ DLL.
What I'm trying to do is real simple and straightforward:
namespace ProtocolDll
{
__delegate void MY_CALLBACK();
[DllImport("test.dll")]
extern "C" void UnmanagedFunc(MY_CALLBACK __gc* myCallback);
public __gc class Wrapper
{
public:
void myCallback()
{
MY_CALLBACK* cb = new MY_CALLBACK(this,&Wrapper::CallMePlease);
UnmanagedFunc(cb); // Call the unmanaged dll function
}
void CallMePlease()
{
Int32 i=0;
i=i+1; // I put a breakpoint here but it never makes it
};
}
************************************
Here is my unmanaged C++ dll code:
typedef void (*MY_CALLBACK)();
EXPORT void UnmanagedFunc(MY_CALLBACK* pfnCallback);
void UnmanagedFunc(MY_CALLBACK* pfnCallback)
{
(*pfnCallback)();
}
Any idea what I am doing wrong? Thanks for any help... this is my last issue with this unmanaged dllimport stuff... this code is a bear to write.
david
|
|
|
|
|
greetings...
im using borland 5.01 and i am trying to interconnect 2 computers with eachother over the internet.
i have to do it with windows (not linux), and it must be DOS (standard).
well, I have only 2 obstacles in my way so far...
1-does anyone know what functions exist for me to connect to a pc, knowing its IP address?
2-does anyone know what functions exist for me to obtain a pc's IP address, knowing its name?
oh, and to use these functions, what libraries must be included and where can i get them?
Thanks
|
|
|
|
|
I'm trying to call a C dll function passing a structure that looks like this:
typedef struct
{
long lModuleID;
DWORD dwAddress;
long lType;
BOOL fComplete;
long lLength;
BYTE *pbyData;
WORD wTimeoutMS;
long lErrors;
} MEMACCESS_STRUCT_S;
I translate this into the following structure in my managed C++ code:
[StructLayout(LayoutKind::Sequential)]
public __gc class MEMACCESS_STRUCT_S
{
public:
Int32 devAddr;
Int32 memAddr; // DWORD (UInt32)
Int32 type;
Int16 complete; // BOOL -> TRUE=1, FALSE=0
Int32 length;
Byte data[];
Int16 timeout; // WORD (UInt16)
Int32 err;
};
Everything works great except the variable "data" that holds the byte array. I get garbage when I look at the values for the array. What am I doing wrong? Thank you so much for any help... I'm nearing the point of headbutting my monitor and throwing my mouse out the window over this one!
david
|
|
|
|
|
|
Thank you for your help. I tried lots of different combinations using the MarshalAs attribute. I eventually ended up pinning (__pin) and assigning my Byte array to an IntPtr in the struct. That worked great!
david
|
|
|
|
|
to write two classes, screen and field, representing a screen
layout and an individual field (either a label or an input region) that
appears on a screen.
The field class, which lets us display, and possibly edit, a character
string, is really intended as a base class from which we'll derive many
kinds of field (displaying/editing different kinds of data) in the
future. Because of this, and because the code for the screen class will
use the field class extensively, it is important that the screen class'
logic uses only features of the field class described below and not
extra features you may decide to add to the field class.
When instantiated a field must be passed between three and five values,
in the following order:
- required: the row on which the field is to be displayed (int)
- required: the starting column for the field (int)
- required: the field's width (int)
- optional: an initial value for the field (constant character string)
- optional: editability flag (true: editable, false: display-only)
If only three parameters are specified, the field begins empty. If fewer
than five parameters are specified, the field is editable. Note that
instantiating a field does not cause it to appear - there are member
functions (below) to do that. If the coordinates specified are not
valid, the closest on-screen coordinates to those specified are used. If
the field width is too long to fit on the screen, the width should be
reduced so that the field fits on the screen. Similarly, if the initial
value is longer than the field width, only as many characters of the
initial value as will fit are used.
A field has the following public member functions, all of which are
virtual:
void display() - causes the field to be displayed on the screen. On
systems where terminal output is buffered, this function does
not flush the screen buffer. Note that if the field's current
value is shorter than the field width, trailing spaces are
displayed to fill out the field. (Such trailing spaces are not
considered part of the data of the field, however).
int edit() - causes the field to be displayed (as in display()) and
then lets the user edit the field, using the keys just as
dt_edit() does. The key code used to terminate editing is
returned. The first time a field's edit() function is called,
the cursor is positioned at the beginning of the field.
Subsequent calls to edit() start the cursor where it left off at
the end of the previous edit() call, unless the string is now
too small (in which case the cursor is positioned just past the
end of the string).
In the case where the field is not editable, this function
simply displays the field and returns 0 without waiting for any
keystrokes.
bool editable() const - returns true if the field is editable, false
if it is display-only.
void *data() - returns the address of the string currently stored by
the field. Note that we expect that in derived classes this may
be the address of some other kind of data being edited.
field *clone() const - dynamically allocates another instance of the
field, making that field a copy of itself, and returns the
address of the copy. If a copy cannot be made, this function
returns NULL. It is the caller's responsibility to deallocate
the copy.
Since dynamic memory allocation is required to implement this properly,
the field class also has an appropriate copy constructor, = operator and
virtual destructor.
A screen manages up to 50 fields (although if you can remove this limit,
you are more than welcomed to do so). The fields are kept in order by
when they were added to the screen - the field that was added first is
known as field number 0, the field that was added next is known as field
number 1 and so on. The screen class has the following public member
functions:
int add(int, int, int) and
int add(int, int, int, const char *) and
int add(int, int, int, const char *, bool) - adds a field to the
screen, where the field added is constructed with the data
supplied to add(). These functions return the number of fields
in the screen after adding the field, or 0 if the field could
not be added for some reason.
int add(const field &f) - adds a copy of "f" to the screen,
returning the number of fields in the screen after adding the
field (or 0 if the add() failed for some reason).
void display() and
void display(bool clear) - displays all the fields managed by the
screen, in the same order that they were added to the screen. If
"clear" is specified and true, the screen is cleared before the
fields are displayed, otherwise the fields are displayed without
touching any other part of the screen. On systems that buffer
terminal output, this function does not flush the output buffer.
int edit() and
int edit(bool clear) and
int edit(int *pfield) and
int edit(int *pfield, bool clear) - Displays all the fields of the
screen (after clearing the screen if "clear" is specified and
true) and then allows the user to edit them, starting at field
number "*pfield". The user moves between fields with any of the
following keys:
Down arrow - moves to the next editable field
Up arrow - moves to the previous editable field
Tab - works just like Down Arrow
Enter - moves to the next editable field, except when pressed
in the last editable field of the screen, in which case it
causes edit() to end.
Here "next" and "previous" refer to the order in which the
fields were added to the screen. There is a wrap-around effect,
also, so the the next field after the last field is the first
field, and the previous field before the first field is the last
field.
All other keys which terminate a field's edit() function
terminate this function as well, setting "*pfield" to the number
of the field from which the user exited. The key code used to
exit the field's edit() is returned.
If "pfield" is NULL or not provided, then editing starts at the
first editable field the first time edit() is called, and
resumes at the field last exited upon subsequent calls.
If "pfield" points to an int, but that int is not the number of
en editable field, then editing begins at the next editable
field (where "next" is as defined above).
If there are no editable fields on the screen, this function
returns 0 after displaying all the fields.
field *getfield(int i) - returns the address of field numbered "i"
or NULL if "i" is not the number of a field.
int remove(int i) - removes field number "i" from the list of fields
being managed by the screen, and returns the number of fields
left on the screen after removal. If "i" is not the number of a
field, then nothing happens and the current field count is
returned.
Note that removing a field renumbers the remaining fields.
Also, the += operator can be used, with a screen on the left and a field
on the right, to add a field to a screen, returning a reference to the
screen.
Note that creating a screen, adding a field to a screen, or removing a
field from a screen causes no immediate visual effect. It is when the
screen is display()ed or edit()ed that the user sees anything.
Note also that since adding a field involves copying the field, and
since we plan to derive new types of field in the future, you must make
the copies of fields by using clone(), rather than by relying on the
copy constructor.
Since this means that your screen must use dynamic memory allocation
(clone() dynamically allocates a copy), you should be sure to code an
appropriate copy constructor, = operator and virtual destructor for the
screen class.
Both the screen class and the field class should be declared in a header
file screen.h, and coded in a source file screen.cpp. Including screen.h
should also make the dtio functions available for use.
|
|
|
|
|
Do your own homework assignment.
If you are stuck with a particular detail then ask for help or advice with that. Do not ask CodeProject members to do your work for you!
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
thanks for replying me back
i am really thankful to you for replying me back.
i am not able to get started and figure out what all things have t be done in this i would be really grateful to you if you can help me in this actually i have source coude which will be used from some previous files i can send you that please tell me ur email address if possible.
|
|
|
|
|
I am coming up with an error of ...
h:\169\program 4\Part.h(52): error C2440: '=' : cannot convert from 'Vendor' to 'Vendor *'
and...
h:\169\program 4\Part.h(52): error C2440: '=' : cannot convert from 'Vendor' to 'Vendor *'
HOW DO I RESOLVE THIS...Here is my line of code it is referring to..
void setVendPtr(Vendor *c_VendPtr) { VendPtr = *c_VendPtr; }
Thanks so much!!!!
~Jason
|
|
|
|
|
if VendPtr is a Pointer then only VendPtr = c_VendPtr;
because c_VendPtr is a pointer itself
|
|
|
|
|
How is this a managed C++ question ?
ISUstudent wrote:
{ VendPtr = *c_VendPtr; }
If c_VendPtr is a Vendor *, then * c_VendPtr is a Vendor, * dereferences the pointer. Remove the *.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
ISUstudent wrote:
void setVendPtr(Vendor *c_VendPtr) { VendPtr = *c_VendPtr; }
VendPtr seem to be a pointer.
two cases for you :
1 - you want to "link" the pointer in parameter to VendPtr. This way, VendPtr and c_VendPtr will point the same address :
<font style="color:blue;">void</font> setVendPtr(Vendor *c_VendPtr) {
VendPtr = c_VendPtr;
}
2 - You prefer create a new copy of the datas pointed to by c_VendPtr and point VendPtr to this new adress :
<font style="color:blue;">void</font> setVendPtr(Vendor *c_VendPtr) {
VendPtr = new Vendor;
*VendPtr = *c_VendPtr;
}
I personnally prefer the second method...
TOXCCT >>> GEII power
|
|
|
|
|
Excellent...I got it!
Thanks a Mill!
|
|
|
|
|
void setVendPtr(Vendor *c_VendPtr)
{
VendPtr = *c_VendPtr;
}
VendPtr // undeclare is a long, so you cannot assign it this way !
void setVendPtr(Vendor *c_VendPtr)
{
Vendor VendPtr;
VendPtr = *c_VendPtr;
}
|
|
|
|
|
Hello all.
I have decided to change the output directory of my managed c++ application and also the intermediate directory.
I had as output and intermediate directories de defaultvalues:
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)
which in fact were the same directory.
I have changed this right now to:
OutputDirectory="o:/$(ConfigurationName)"
IntermediateDirectory="o:/$(ConfigurationName)/Intermediate/$(ProjectName)
This changes the output of the project and the project is build correctly but when I try to execute the application I get a System.Resources.MissingManifestException.
If I don't modify the original value for the intermediate directory it works fine
Please can anyone explain something to me ???
Thanks in advace.
|
|
|
|
|