Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > .NET Frameworks (точка нет фреймворки) > C# (си шарп)
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 24.08.2011, 17:36   #1
truppik
Новичок
Джуниор
 
Регистрация: 24.08.2011
Сообщений: 2
Сообщение аналог Message но в Dll

Хай всем!
Есть проект по работе с General HID устройствами (с сайта http://www.Lvr.com).
Так вот. Сейчас переоформляю все это в отдельную Dll с необходимыми мне public функциями для работы (с МК). И наткнулся на такую проблемку, код в файле DeviceManagement :
Код:
internal Boolean DeviceNameMatch(Message m, String mydevicePathName)
		{
			Int32 stringSize;

			try
			{
				DEV_BROADCAST_DEVICEINTERFACE_1 devBroadcastDeviceInterface = new DEV_BROADCAST_DEVICEINTERFACE_1();
				DEV_BROADCAST_HDR devBroadcastHeader = new DEV_BROADCAST_HDR();

				// The LParam parameter of Message is a pointer to a DEV_BROADCAST_HDR structure.

				Marshal.PtrToStructure(m.LParam, devBroadcastHeader);

				if ((devBroadcastHeader.dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE))
				{
					// The dbch_devicetype parameter indicates that the event applies to a device interface.
					// So the structure in LParam is actually a DEV_BROADCAST_INTERFACE structure, 
					// which begins with a DEV_BROADCAST_HDR.

					// Obtain the number of characters in dbch_name by subtracting the 32 bytes
					// in the strucutre that are not part of dbch_name and dividing by 2 because there are 
					// 2 bytes per character.

					stringSize = System.Convert.ToInt32((devBroadcastHeader.dbch_size - 32) / 2);

					// The dbcc_name parameter of devBroadcastDeviceInterface contains the device name. 
					// Trim dbcc_name to match the size of the String.         

					devBroadcastDeviceInterface.dbcc_name = new Char[stringSize + 1];

					// Marshal data from the unmanaged block pointed to by m.LParam 
					// to the managed object devBroadcastDeviceInterface.

					Marshal.PtrToStructure(m.LParam, devBroadcastDeviceInterface);

					// Store the device name in a String.

					String DeviceNameString = new String(devBroadcastDeviceInterface.dbcc_name, 0, stringSize);

					// Compare the name of the newly attached device with the name of the device 
					// the application is accessing (mydevicePathName).
					// Set ignorecase True.

					if ((String.Compare(DeviceNameString, mydevicePathName, true) == 0))
					{
						return true;
					}
					else
					{
						return false;
					}
				}
			}
			catch (Exception ex)
			{
				throw;
			}

			return false;
		}
и соответственно вызывающий эту функцию код :
Код:
internal void OnDeviceChange( Message m ) 
        {             
            Debug.WriteLine( "WM_DEVICECHANGE" ); 
            
            try 
            {
                if ((m.WParam.ToInt32() == DeviceManagement.DBT_DEVICEARRIVAL)) 
                {                     
                    //  If WParam contains DBT_DEVICEARRIVAL, a device has been attached.
                    
                    Debug.WriteLine( "A device has been attached." ); 
                    
                    //  Find out if it's the device we're communicating with.
                    
                    if ( MyDeviceManagement.DeviceNameMatch( m, myDevicePathName ) ) 
                    { 
                        lstResults.Items.Add( "My device attached." ); 
                    } 
                    
                }
                else if ((m.WParam.ToInt32() == DeviceManagement.DBT_DEVICEREMOVECOMPLETE)) 
                { 
                    
                    //  If WParam contains DBT_DEVICEREMOVAL, a device has been removed.
                    
                    Debug.WriteLine( "A device has been removed." ); 
                    
                    //  Find out if it's the device we're communicating with.
                    
                    if ( MyDeviceManagement.DeviceNameMatch( m, myDevicePathName ) ) 
                    { 
                        
                        lstResults.Items.Add( "My device removed." ); 
                        
                        //  Set MyDeviceDetected False so on the next data-transfer attempt,
                        //  FindTheHid() will be called to look for the device 
                        //  and get a new handle.
                        
                        FrmMy.myDeviceDetected = false; 
                    } 
                }                 
                ScrollToBottomOfListBox();                 
            } 
            catch ( Exception ex ) 
            { 
                ExLog.ExceptionWrite(this.Name, ex);
                throw ; 
            } 
        }
Message конечно же выдаёт ошибку, т.к. это не Form приложение...
Помогите пожалуйста решить эту проблему..
truppik вне форума Ответить с цитированием
Старый 24.08.2011, 17:42   #2
truppik
Новичок
Джуниор
 
Регистрация: 24.08.2011
Сообщений: 2
По умолчанию

а OnDeviceChange(m) вызываеться собственно так :
Код:

protected override void WndProc( ref Message m ) 
        {            
            try 
            { 
                //  The OnDeviceChange routine processes WM_DEVICECHANGE messages.
                
                if ( m.Msg == DeviceManagement.WM_DEVICECHANGE ) 
                { 
                    OnDeviceChange( m ); 
                } 
                
                //  Let the base form process the message.
                
                base.WndProc( ref m );                 
            } 
            catch ( Exception ex ) 
            { 
                ExLog.ExceptionWrite(this.Name, ex);
                throw ; 
            }             
        }
получается Message хранит аналог структуры DeviceManagement.WM_DEVICECHANGE, что значит, чт необходимо создать анологичный экземпляр структуры с функциями или я не правильно понял ?
truppik вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Ereaderror with message s1s1s1 Общие вопросы Delphi 0 20.07.2011 14:08
The message resource is present but the message is not found in the string/message table Apokal Win Api 0 19.05.2011 18:06
DLL. Project *.exe faulted with message: 'priveleg instruction at 0x...'. Proccess stopped. TwiX Общие вопросы Delphi 2 26.12.2009 14:34
Message-ы Altera Общие вопросы Delphi 9 15.02.2008 09:08
Send Message _SERGEYX_ Работа с сетью в Delphi 5 30.10.2007 06:38