Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
Y

yehiga1467

@yehiga1467
About
Posts
15
Topics
8
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Convert/cast System::Array class to List
    Y yehiga1467

    How do I convert array to list?

      array^ My1DArray = gcnew array(100);
    

    to

    List^ temp

    temp = My1DArray.ToList(); //doesn't work

    Update: I am currently using a for loop to copy data 1 by 1, if there's no other faster way ,i'll stick with this for now . Thanks!

    array^ My1DArray = gcnew array(100);

    int^ bytesToRead = gcnew(int);
    *bytesToRead = SerialPort->BytesToRead;
    SerialPort->Read(My1DArray, 0, *bytesToRead);
    SerialPort->DiscardInBuffer();

    List^ temp = gcnew List;

    int^ counter = gcnew (int);
    for (*counter = 0; *counter < *bytesToRead; (*counter)++) {
    temp->Add(My1DArray[*counter]);
    }

    Managed C++/CLI question data-structures announcement

  • Managed c++ how to memcpy a handle reference
    Y yehiga1467

    Thank you very much Richard for elaborating a bit on this! I have solved my problem !

    Managed C++/CLI c++ help tutorial question

  • Managed c++ how to memcpy a handle reference
    Y yehiga1467

    Hello, I am trying to memcpy two managed values. The link provided seem to be for unmanaged to managed? Could you show an example how to achieve this? Thanks!

    Managed C++/CLI c++ help tutorial question

  • Managed c++ how to memcpy a handle reference
    Y yehiga1467

    how do you copy the bytes of a managed variable to another managed variable? memcpy doesn't work since my arguments are not the correct type for memcpy

    #include "string.h" //Updated Solution
    float^ f = gcnew (float);
    unsigned int^ temp = gcnew(unsigned int);
    *temp = 0;
    *temp = _byte3;
    *temp = (*temp << 8U) + _byte2;
    *temp = (*temp << 8U) + _byte1;
    *temp = (*temp << 8U) + _byte0

    // memcpy(f, temp,4U); //error

    **//Updated solution :

    	pin\_ptr pinPtr\_FloatVal = &(\*f);
    
    
    	pin\_ptr pinPtr\_UintVal = &(\*temp);
    
    
    memcpy\_s(pinPtr\_FloatVal , 4U, pinPtr\_UintVal , 4U); //4U i.e. 4 bytes**
    
    Managed C++/CLI c++ help tutorial question

  • Weird button click event for button with same EventHandler
    Y yehiga1467

    I have 2 buttons on my form and they're calling the same function when clicked. When button 1 is clicked, the event handler is called. I then debug and read the sender's name in the event handler and see that button 2 was the one being clicked.(same applies when pressing button 2, button 1 becomes the sender's name) This situation happens randomly without pattern, and quite frequently 8/10 times when I click the button. I have no idea what's the reason to this! MyForm.h

    #include "Common_Groupbox.h"
    .
    .
    .
    private: System::Windows::Forms::Button^ Button1;
    private: System::Windows::Forms::Button^ Button2;

    private: Common_Groupbox^ groupbox1;
    private: Common_Groupbox^ groupbox2;
    .
    .
    .
    private: System::Void MyForm::MyForm_Load(System::Object^ sender, System::EventArgs^ e) {

    groupbox1 = gcnew Common\_Groupbox(Button1);
    groupbox2 = gcnew Common\_Groupbox(Button2);
    

    }

    Common_Groupbox.h

    private: System::Windows::Forms::Button^ _myButton;

    public:
    Common_Groupbox( System::Windows::Forms::Button^ myButton) {

        \_myButton = myButton;
        \_myButton->Click += gcnew System::EventHandler(this, &Common\_Groupbox::myButton\_Clicked);
    
    }
    
    public: System::Void myButton\_Clicked(System::Object^ sender, System::EventArgs^ e) {
        // do something 
    
    }
    
    Managed C++/CLI debugging regex

  • How to make Serial Port static from the designer?
    Y yehiga1467

    Thanks I have been adding the static keyword manually. But do you know if there is a way to automatically do this?

    Managed C++/CLI design tutorial question

  • How to make Serial Port static from the designer?
    Y yehiga1467

    Hello all, my code requires the Serial Port to be static. Each time I make changes to the UI, I have to manually set the Serial Port to static. like this

    private: System::IO::Ports::SerialPort^ mySerialPort;

    to this

    private: static System::IO::Ports::SerialPort^ mySerialPort;

    Is there a way to automatically be static?

    Managed C++/CLI design tutorial question

  • Managed c++ float/double/integer to String and vice-versa?
    Y yehiga1467

    Hello, I have tried ToString(), but I could not format to the how many decimal places to display .

    Managed C++/CLI question c++

  • Button image is not updating to new image when Serial Port received new data
    Y yehiga1467

    Hello jsc42, yes I have done this part to prevent the user from ever mistakenly clicking the button :) . Thanks for the suggestion!

    Managed C++/CLI question data-structures help announcement

  • Managed c++ float/double/integer to String and vice-versa?
    Y yehiga1467

    Hello, I am trying to display float/double/integer to a string with custom format in Label. But I couldn't find snprintf available in managed c++. How can I achieve this?

    Managed C++/CLI question c++

  • Button image is not updating to new image when Serial Port received new data
    Y yehiga1467

    Hello, I seen that this Refresh() should force the button to redraw itself, and I tested but it still didn't work. I then guessed that the button was disabled and I was right, because the button is disabled it couldn't show the new background image. Thanks for your help!

    Managed C++/CLI question data-structures help announcement

  • Button image is not updating to new image when Serial Port received new data
    Y yehiga1467

    I am trying to set the image of a button when my Serial Port receives data. After I receive the data, I use an Invoke to call MyForm::ProcessReceived, then from the MyForm::ProcessReceived to setAppearance. My setAppearance function is called, however the image on button is still showing the default image. How do I show the new image in button?

    System::Void MyForm::SerialPort\_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e)
    {
    	uint16\_t test = 0;
    
    	test = mySerialPort->BytesToRead;
    
    
    		this->Invoke(gcnew EventHandler(this, &MyForm::ProcessReceived));
    
    }
    
    
    	System::Void MyForm::ProcessReceived(System::Object^ sender, System::EventArgs^ e) {
    
        // my\_ReceivedData is just a custom class to parse & store received data
    	my\_ReceivedData^ status = gcnew my\_ReceivedData;
    
    
    	mySerialPort->Read(status->bytes, 0, length);
    	mySerialPort->DiscardInBuffer();
    
    	setAppearance(status->bytes);
    
    }
    
    
    public: System::Void setAppearance(array^ bytes) {
        btn\_Start->ImageIndex = 3; // function is excecuted, but image is still not updated from it's default
    }
    

    Update (Problem solved): It turned out that the buttons were disabled so the background images couldnt be updated. After enabling the buttons, everything worked accordingly!

    Managed C++/CLI question data-structures help announcement

  • How to pass a function pointer an argument in managed C++
    Y yehiga1467

    Hello, I have made to test() to static and now I have a new error at the same line that doesn't make sense to me. argument of type "void (*)(int, char*)" is incompatible with parameter of type "void (*)(int, char*)" Both the types are identical. I have also tried to change all types to void, and the error message is still the same i.e. argument of type "void (*)()" is incompatible with parameter of type "void (*)()" latest update: problem solved. Please see the first post! thanks!

    Managed C++/CLI help question c++ testing beta-testing

  • How to pass a function pointer an argument in managed C++
    Y yehiga1467

    I am trying to call a function defined in the parent class via the object. But I am getting the error a pointer to member is not valid for a managed class. How can I achieve what I wanted? My expected output is to display the text "Called from child"

    MyChild.h
    ref class MyChild
    {

       System:Void(\*my\_func\_ptr)(int, char\*);
       typedef System:Void(\*MyFuncPtrType)(int, char\*);
       MyFuncPtrType my\_func\_ptr;
    
    
    public: MyChild ( System:Void(\*some\_func)(int, char\*)){
    
    	my\_func\_ptr = some\_func;
    }
    
    public: System::Void  Child\_ButtonClicked(System::Object^ sender, System::EventArgs^ e){
    	my\_func\_ptr();
    }
    

    }

    MyForm.h

    #include "MyChild.h"

    public ref class MyForm : public System::Windows::Forms::Form
    {
    .
    .
    .
    private: static System:Void test(int, char*) { //Update
    MessageBox::Show("Called from child");
    }

    private: System::Void MyForm::MyForm\_Load(System::Object^ sender, System::EventArgs^ e) {
    	MyChild^ child= gcnew MyChild( **MyForm::test**); **//type incompatible error in this line**
    	child -> test(1,"random");
    }
    

    }

    Update 2, Previous problem for //type incompatible error in this line is solved using the following way below.

    MyChild.h
    ref class MyChild
    {

    private:     System::Void(\*my\_func\_ptr)(int, char\*);
    
    public:	System::Void doFunction(int A, char\* B) {
           (\*my\_func\_ptr)(A,B);
       }
    
    
    public: MyChild ( System::Void(\*func)(int A, char\* B)){
    
    	my\_func\_ptr = func;
    }
    
    public: System::Void  Child\_ButtonClicked(System::Object^ sender, System::EventArgs^ e){
    	doFunction(1,"random");  //the arguments here are not used in later program, it is just for testing a function ptr with arguments
    }
    

    }

    MyForm.h

    #include "MyChild.h"

    public ref class MyForm : public System::Windows::Forms::Form
    {
    .
    .
    .

       typedef System::Void (\*callback\_function)(int, char\*); 
       
       
    private: static System:Void test(int, char\*) {
    	MessageBox::Show("Called from child");
    }
    
    
    private: System::Void MyForm::MyForm\_Load(System::Object^ sender, System::EventArgs^ e) {
    
    
    callback\_function disc;
    
    disc = (callback\_function)(MyGUI::MyForm::test);
    
    	MyChild^ child= gcnew MyChild( **disc**);
    	child -> doFunction(1,"random");
    }
    

    }

    For now, everything is solved but I am still unsure to the reason for incompatibility for argument and parameter having same type. I will do more trails and see if this is a stable

    Managed C++/CLI help question c++ testing beta-testing

  • Serial Port BytesToRead always 0
    Y yehiga1467

    Hello everyone, I made a class that will do some additional configuration to the serial port. (Mainly to handle received data). My issue is that SerialPort_DataReceived() is successfully triggered when it received data from device, however the BytesToRead is always 0. What could the reason be? I am sure the device is sending data because when I haven't use this ConfigSerialPort, everything works fine. ConfigSerialPort.h

    #pragma once
    using namespace System::Windows::Forms;

    ref class ConfigSerialPort: public System::Windows::Forms::Control
    {

    private: System::IO::Ports::SerialPort^ \_serialPort;
    
    public:
    	ConfigSerialPort(System::IO::Ports::SerialPort^ serialPort) {
    		\_serialPort = serialPort;
    		
        //handle received data
    		\_serialPort->DataReceived += gcnew System::IO::Ports::SerialDataReceivedEventHandler(this, &ConfigSerialPort::SerialPort\_DataReceived);
    	
    	}
    	
    private: 	System::Void SerialPort\_DataReceived(System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e)
    {
        unsigned int test = 0;
    
        test = \_serialPort->BytesToRead; **// BytesToRead is ALWAYS Zero**
    }
    

    }

    MyForm.h

    #pragma once

    #include #include #include #include #include "ConfigSerialPort.h"

    namespace SerialPortGUI {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    
    using namespace System::IO;
    using namespace System::Runtime::Serialization::Formatters::Binary;
    
    
    
    
    
    
    /// /// Summary for MyForm
    /// 
    public ref class MyForm : public System::Windows::Forms::Form
    {
    	public:
    		MyForm(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Add the constructor code here
    			//
    		}
    		.
    		.
    		.
    		
    		
    		void InitializeComponent(void)
    		{
    			.
    			.
    			.
    			this->Load += gcnew System::EventHandler(this, &MyForm::MyForm\_Load);
    		   this->MyForm\_SerialPort = (gcnew System::IO::Ports::SerialPort(this->components));
    		   
    			.
    			.
    			.
    
    		}
    	private: ConfigSerialPort^ test;
    	private: System::Void MyForm\_Load(System::Object^ sender, System::EventArgs^ e) {
    	
    	// initialize Serial port (already done via the designer)
    	test = gcnew ConfigSerialPort(MyForm\_SerialPort);
    	
    	}
    }
    

    }

    Managed C++/CLI graphics json help question workspace
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups