|
Why is this code throwing exception
gameBoard->gameBtns = gcnew array<Button^>(GameBoard::TOTAL_BOXES);
for each(Button^ btn in gameBoard->gameBtns)
btn->Enabled = true;
where TOTAL_BOXES is defined as 9
but this code doesn't
Button^ temp = gcnew Button();
temp->Enabled = true;
|
|
|
|
|
Hi,
Ahmed Manzoor wrote: Button^ temp = gcnew Button();
creates a button, so you can operate on it.
Ahmed Manzoor wrote: gameBtns = gcnew array<button^>(GameBoard::TOTAL_BOXES);
Does not generate any buttons, all it does is generate an array that will be able to hold some buttons.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
so I'll have to generate each button individually?
|
|
|
|
|
Ahmed Manzoor wrote: so I'll have to generate each button individually?
Yes. You did it when you needed one, what makes you think you don't have to when you want a lot of them?
BTW: array elements are initialized to null; you only need to create as many buttons as you need, you
can leave the non-essential elements, if any, at null.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I want to know the difference between managed and unmanged code..
Thanks
vikas da
|
|
|
|
|
|
Hi,
I have a C++ library app which talks to a C++ server and I am creating a vectorje of my custom class objects. But my Cpp/CLI app(which interacts with native C++ ), throws a memory violation error when I try to return my custom class obj vector.
Code Sample -
In my native C++ class -
std::vector<a> GetStuff(int x)
{
-- do stuff
std::vector<a> vec;
A a;
vec.push_back(a);
--- push more A objs
return vec;
}
In my Cpp/CLI class
public void doStuff()
{
std::vector<a> vec;
vec = m_nativeCpp->GetStuff(4); // where nativeCpp is a dynamically allocated class in nativecpp DLL, the app throws up a memory violation error here!
}
Anything I am missing here ?What should be the ideal way to return such an array -
Regards
Amit </a></a></a>
|
|
|
|
|
Type A is created on stack and this may be the problem. Have you tried to allocate it on heap and let vector hold a pointer to it. I believe that will solve the issue. I haven't tried this, but a wild guess.
Member 5703905 wrote: throws up a memory violation error
What is the exact error message?
|
|
|
|
|
Okay, but I wanted to convey that nativeC++ DLL and Cpp/CLI DLL are in diff projects. Not sure if it is a nice idea to return a ptr from unmanaged project to managed cpp/cli project.
N a v a n e e t h wrote: What is the exact error message?
An unhandled exception of type 'System.AccessViolationException' occurred in CLIConsole.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Thanks
Amit
|
|
|
|
|
Member 5703905 wrote: Not sure if it is a nice idea to return a ptr from unmanaged project to managed cpp/cli project.
It's fine in C++/CLI. Native objects will be on the native heap, managed objects
will be on the managed heap. If you need to hold the pointer in a managed object, you
can use the IntPtr type.
If you expect to allocate the native object in one DLL and free it in another DLL, you'll
want to make sure both DLLs are sharing the same CRT library (DLL).
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
In VC++ I want to execute .exe using ShellExecute command. But ShellExecute works for hardcoded file names. Suppose that if I want to pass a file selected by the user i.e.this->openFileDialog1->FileName in ShellExecute, how should I do that?
::ShellExecute(NULL, L"open", L"C:\\play.bat", this->openFileDialog1->FileNameNULL, SW_SHOW);
gives error : cannot convert from 'System::String ^' to 'LPCTSTR'
even using ((LPCTSTR)this->openFileDialog1->FileName)doesn help
|
|
|
|
|
|
HI
I need hook events of keyboard in my app, this is made in managed c++, i did one dll in c++ for hook keyboard and this run good.
first i did simple app in C for test my dll and using SetWindowsHookEx
BOOL HazHook()
{
HOOKPROC hkprcSysMsg;
HPROC hkprcSysMsg2;
HINSTANCE hinstDLL;
HHOOK hhookSysMsg;
hinstDLL = LoadLibrary((LPCTSTR) "keyboard.dll");
if ( hinstDLL != NULL)
{
OutputDebugString ( "1> OK\n");
hkprcSysMsg2 = (HPROC)GetProcAddress(hinstDLL, "_keyboardHookProc@12");
if ( hkprcSysMsg2 != NULL)
{
OutputDebugString ( "2> OK\n");
// LocalhPrevInstance is hPrevInstance of WinMain app.
hhookSysMsg = SetWindowsHookEx(WH_KEYBOARD_LL,hkprcSysMsg2,hinstDLL,LocalhPrevInstance); // original
if( hhookSysMsg != NULL)
{
OutputDebugString ( "3> OK\n");
return TRUE;
}
else OutputDebugString ( "3> FAIL\n");
}else OutputDebugString ( "2> FAIL\n");
}else OutputDebugString ( "1> FAIL\n");
return FALSE;
}
The problems start whemn I need use SetWindowsHookEx in Managad C++, I try inport API but the conversion of rates I not know, HOOKPROC, HINSTANCE , DWORD is unsigned int
[DllImport("user32.dll")]
static int SetWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hMod,DWORD dwThreadId);
Other try is using unamanged C++
#include "stdafx.h"
#pragma unmanaged
#include <windows.h>
#include <stdio.h>
typedef LRESULT (CALLBACK *HPROC)(int , WPARAM , LPARAM );
bool lalaLoadDllKeyboard()
{
HOOKPROC hkprcSysMsg;
HPROC hkprcSysMsg2;
HINSTANCE hinstDLL;
HHOOK hhookSysMsg;
hinstDLL = LoadLibrary( "keyboard.dll");
if ( hinstDLL != NULL)
{
hkprcSysMsg2 = (HPROC)GetProcAddress(hinstDLL, "_keyboardHookProc@12");
if ( hkprcSysMsg2 != NULL)
{
OutputDebugString ( "2> OK\n");
//hhookSysMsg = SetWindowsHookEx(WH_KEYBOARD_LL,hkprcSysMsg2,hinstDLL,LocalhPrevInstance); // original
hhookSysMsg = SetWindowsHookEx(WH_KEYBOARD_LL,hkprcSysMsg2,hinstDLL,0); // original
if( hhookSysMsg != NULL)
{
OutputDebugString ( "3> OK\n");
return true;
}
}
}
return false;
}
#pragma managed
But to compile errors:
1>------ Operación Generar iniciada: proyecto: WinFormsHookKeyboard, configuración: Debug Win32 ------
1>Vinculando...
1>codeunamanged.obj : error LNK2019: símbolo externo _SetWindowsHookExA@16 sin resolver al que se hace referencia en la función "bool __cdecl lalaLoadDllKeyboard(void)" (?lalaLoadDllKeyboard@@YA_NXZ)
Any idea ??
Thank
|
|
|
|
|
Kar98 wrote: I try inport API but the conversion of rates I not know, HOOKPROC, HINSTANCE , DWORD is unsigned int
pinvoke.net: SetWindowsHookEx()[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
I'm new in Visual C++.I want to convert row elements from two dimensional array to one dimensional arrays.I wrote Visual C++ function to do this.This function has only one input parameter.Input parameter is two dimensional array.Firstly I tried to copy first row elements of input two dimensional array to one dimensional array in this function.One dimensional array will have been output parameter of function.But it didn't work.
The code is below:
// Temp is one dimensional array its length is 512
// Input paremeter is two dimensional array its width is 512 ,height is 512
// I want to copy first row elements of input two dimensional array to one dimensional array.
array^ fonksiyon (array<double,2>^dizi )// The function
{ array^ temp=gcnew array(512);
Array::Copy(dizi,temp,512);
return temp;// return one dimesional array
}
Could you please help me ? Best regards...
|
|
|
|
|
Hey everyone... I need some assistance getting an image from a string.
I have an RTF text box into which a user can paste an image. However, I'd like to take this image out of the RTF and store is elsewhere. The System.Drawing.Image class has a function called FromString but I can't seem to figure out how to correctly use it. I've also looked at the System.Drawing.ImageConverter class but that hasn't helped either.
Can anyone tell me how to get this image out of the rtf and into a bitmap object?
Thanks,
Sam.
|
|
|
|
|
OO... i mean the imageconverter class has a function called "FromString" - not the image class...
|
|
|
|
|
There is a DrawToBitmap[^] method for control. Have you tried that?
Edit:
Aahh, I have seen that documentation[^] saying it is not fully functional with rich textbox.
|
|
|
|
|
i am developing a application which has got a admin module and a user module, admin module will be running on only one machine, but the user modules will be running on multiple systems. i have got some settings to be done in admin module and the same settings should be used by user module also, how to get the settings in the user module from the admin machine. whenever any settings are changed in admin module all the user modules should get the new settings.
please help me out of this
Naveen
modified on Friday, January 30, 2009 2:38 AM
|
|
|
|
|
Hi. I have a synchronous socket listening for tcp connections with a pending size of 1. When a connection request is received, its accepted and processed. But after I am done with that connection and release resources, eventhough the server socket is listening state, it doesn^t accept new connections and blocks forever. What can be the reason?
Also, is there any way to empty the pending queue of a socket?
Thanks
|
|
|
|
|
randomVariable wrote: I have a synchronous socket listening for tcp connections with a pending size of 1
Post that code
randomVariable wrote: it doesn^t accept new connections
What error message does the connecting socket receive?
|
|
|
|
|
The socket is innocent, seems like it was my fault at another part of the code. Anyway, the problem is solved. Thank you very much for your reply.
|
|
|
|
|
May I know what the problem was?
ty
|
|
|
|
|
I have inserted the mschart into window form of visual c++ 2008, but there is very little articles talking about how to use it in c++ , does anyone know how to use it?Thanks.
|
|
|
|
|
Here[^] is a C# implementation. Converting that to C++/CLI will be trivial.
|
|
|
|