|
Sometimes there is no object behind the interface pointer at all, only the set of functions.
With best wishes,
Vita
|
|
|
|
|
Hello,
i need to convert a system.__comobject to a byte[] in C# .Net
greetings,
Sander
|
|
|
|
|
Sander1234321 wrote: i need to convert a system.__comobject to a byte[] in C# .Net
I suppose if you know the size of the com object in bytes you can marshal the memory into managed memory, however my guess is that is not what you want.
|
|
|
|
|
i tried that with the following code:
int structsize = System.Runtime.InteropServices.Marshal.SizeOf(obj);
but it raises an error namely: "Type 'System.__ComObject' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed."
greetings,
Sander
|
|
|
|
|
Sander1234321 wrote: but it raises an error namely: "Type 'System.__ComObject' cannot be marshaled as an unmanaged structure; no meaningful size or offset can be computed."
DUH, that's why I said:
led mike wrote: I suppose if you know the size of the com object in bytes
I also said:
led mike wrote: however my guess is that is not what you want.
I have nothing new to add so this post is completely redundant.
|
|
|
|
|
I have written a COM DLL which gives the
out parameter as BSTR**(Typically 2D Char Array).
This COM function will fill the values of BSTR** variable.
I am able to use this function sucessfully in MFC Application.
But I face problem in using it in C#.
The Sample code is as follows:
///////////COM Function////////////////////////////////////////
STDMETHODIMP CSampleTest::GetAllDeviceList2(BSTR** szMaclist)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
for(int i=0;i<10;i++)
{
szMaclist[i] = new BSTR[100];
wchar_t *szTmp = new wchar_t[100];
wsprintf(szTmp,L"Device%d",i+1);
*szMaclist[i]=SysAllocString(szTmp);
}
return S_OK;
}
///////////////////////////////////////////////////////////////
I acessed this in VC++ by,
BSTR **szMaclist = new BSTR*[10];
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,iid,(void**)&pText);
if( SUCCEEDED(hr) )
{
pText->GetAllDeviceList2(szMaclist);
pText->Release();
}
and i am sucessful in acessing this function in MFC Application.
Can anyone tell me how to acess GetAllDeviceList2() function in c#.
|
|
|
|
|
Try using SAFEARRAYs rather than standard C arrays. That way, there should be metadata in the type library or something that can help the process.
This CP article[^] might help
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.TypeInitializationException: The type initializer for 'AMP.mdlCaiDat' threw an exception. ---> System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
at AMP.mdlCaiDat..cctor()
--- End of inner exception stack trace ---
at AMP.mdlCaiDat.InsertTimeAll(String idcard, String TimeInOut, String tablename, Byte TongSLC)
at AMP.mdlFnRac.FN_save(Byte p_id)
at AMP.frmRac.btnDownloadData_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
AMP
Assembly Version: 2.0.0.1
Win32 Version: 2.0.0.1
CodeBase: file:///D:/PM%20cham%20cong%20AMP/Chuong%20trinh/AMP.exe
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 8.0.0.0
Win32 Version: 8.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
KTMDK
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///D:/PM%20cham%20cong%20AMP/Chuong%20trinh/KTMDK.DLL
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Transactions
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
Interop.Excel
Assembly Version: 1.5.0.0
Win32 Version: 1.5.0.0
CodeBase: file:///D:/PM%20cham%20cong%20AMP/Chuong%20trinh/Interop.Excel.DLL
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
|
|
|
|
|
Error 0x80040154 indicates you haven't registered your COM component. Registration-free COM interop[^] might be want you want.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I was trying to write COM wrapper for a 3rd party .net library (basically wrote few functions based on that library). So, I followed all the steps given in the msdn site, and VB6 IDE was detecting it fine and all the implemented functions were showing up correctly, but there is one problem. Nothing was working and program was crashing at point where those functions were referenced, because it just see the wrapper but doesn’t find the actual library, My question is, what I am doing wrong? Is there any way I can wrap my COM wrapper and library together?
Thank you,
Arya
|
|
|
|
|
Dear all,
I am having an out of memory problem in Matlab with using a proprietary DLL to read data that was recorded using that company's software and equipment.
I have went through the problem with the software engineer at the company and he is quite certain that it is not due to leaking memory because the DLL only creates the memory object once and reuses it.
The DLL (data reader) is loaded using the actxserver command in matlab. The DLL retrieves data based on events, so I registered the event using: registerevent({'DataReady' 'DataReady_function'});
That is, when the user asks for data, the DLL sends it back via the event callback function in Matlab: 'DataReady_function'.
I have inserted "clear VARIABLES" throughout the functions to ensure that I have cleared all variables that were no longer used. When the data came in via the event handler as "varargin", I even loaded everything in (i.e., FULL_DATA = varargin) and taken out the data (i.e., Data = varargin{7}) and then applied "clear" to the whole "varargin" (i.e., clear FULL_DATA).
The problem is that as I loop through the function, reading through the stored data on the hard drive, more and more memory gets held up by Matlab, even though I am not actually storing any data within Matlab (just consistently reading in small bits of data and then clearing it). If I let it keep running, Matlab eventually runs out of memory. If I stop it before it runs out and try to "clear all", Matlab still holds onto the memory and will not release it (I confirmed this by looking at the memory usage under the processes tab in Windows Task Manager).
From what I can gather, Matlab must be trying to protect all the bits of data that comes in via the event callback, but I just don't know how to tell Matlab that the data has been read and it does not need to protect it any longer. If you have encountered this problem or know how to resolve it, please let me know.
I am really stuck and would really appreciate your help. Thank you very much.
Yours sincerely,
Alan
|
|
|
|
|
LaiAlan wrote: I am having an out of memory problem in Matlab
How have you verified this?
Did MatLab crash due to low memory or did it display a message that told you it was running low on memory?
If you base all this on the figures in Task Manager you should really have a look at this article[^].
LaiAlan wrote: If I let it keep running, Matlab eventually runs out of memory.
Have you actually experienced this?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Yes, Matlab crashed due to low memory. The actual error message is:
??? Out of memory. Type HELP MEMORY for your options.
Error in ==> comeventcallback at 3
args = hEvent.get;
Warning: Error occurred while evaluating listener callback.
After it has ran out of memory and stopped "reading and clearing data" (i.e., I did it to make sure it doesn't use more and more memory), "clear" did not change the memory used by Matlab at all:
>> memory
Maximum possible array: 8 MB (8.389e+006 bytes) *
Memory available for all arrays: 69 MB (7.256e+007 bytes) **
Memory used by MATLAB: 2767 MB (2.901e+009 bytes)
Physical Memory (RAM): 3326 MB (3.487e+009 bytes)
|
|
|
|
|
LaiAlan wrote: ??? Out of memory. Type HELP MEMORY for your options.
Error in ==> comeventcallback at 3
args = hEvent.get;
Warning: Error occurred while evaluating listener callback.
This looks interesting. It looks like an error message from MatLab
To me it seems reasonable that such an error won't occur unless the application is trying to allocate memory. The text "Error occurred while evaluating listener callback", makes me suspect that this error occurs before your callback is called.
The above suggests that MatLab is allocating memory internally prior to calling your callback. This could be due to how the callback interface is declared.
What does the callback interface look like? Post the declaration of it.
If you don't allocate any memory in your callback and the third party DLL doesn't allocate memory when calling your callback, then it must be some kind of internal MatLab stuff that is going on and it should be possible to find in the MatLab documentation.
Have you tried writing another client to avoid MatLab related stuff with e.g. MFC?
What happens?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Dear Roger,
Thank you very much for your reply.
The following is a section of the code in the Connect.m function that does all the initialisation (creates the actxserver, opens the data file using a method of the DLL, creating the data reader interface and registering the event callbacks to retrieve data):
%--------------------------------------------------------------------------
% Load Study Interface (ACTUALLY, it is a COM Server in Matlab, not an
% interface).
gIStudy = actxserver('CMEEGStudyV4.Study');
% Open the study.
gIStudy.Open(FilePath,0) % File path name
% Determine the sampling rate and the number of channels in the study.
SampleRate = gIStudy.get('EEGSampleRate');
gSampleRate = SampleRate;
IChannels = gIStudy.get('Channels');
TotalChs = IChannels.count;
clear IChannels
gTotalChs = TotalChs;
% Determine how many data segments there are in the study.
IDataSegs = gIStudy.get('DataSegments');
NumDataSegs = IDataSegs.count; % A data segment is like a 'Block' in TDT.
% The data segments' start times are all referenced to a single time point.
% That is, the second data segment's start time is always later than the
% first data segment's start time plus the first data segment's duration.
% Create the Data Reader (Interface).
DataReader = gIStudy.CreateDataReader;
DataReader.registerevent({'DataReady' 'DataReady_TEST'});
DataReader.registerevent({'NoData' 'NoData_TEST'});
%--------------------------------------------------------------------------
I have a Get_Data.m function that the user specifies the start time and duration of the data required from the data file. The Get_Data.m function has a line of code that uses the data reader in the DLL to request the data:
%--------------------------------------------------------------------------
DataReader.SGetDataEx(StartSample,NumberofSamples);
while ~gDataRetrieved % gDataRetrieved is a global variable
pause(0.0001) % Stay in this while loop until all the data has been retrieved.
end
gDataRetrieved = false; % Reset the DataRetrieved flag
%--------------------------------------------------------------------------
In the event callback function (DataReady.m), all it does is read in the data:
%--------------------------------------------------------------------------
gDataMat = varargin{7}; % When a registered event is triggered, Matlab passes information
% from the event to its handler function as a cell.
% It is the 7th cell because 1-2 are Matlab stuff.
% 3-6 are some data info retrieved by the DLL.
I have narrowed down the source of the problem by using the Matlab "memory" command throughout the functions. In particular,
memory usage = 518MB
memory (i.e., "memory" command before the datareader line)
DataReader.SGetDataEx(StartSample,NumberofSamples) % This will trigger the DataReady.m to read data
memory usage = 597MB
Just as it enters the DataReady.m function (i.e., "memory" command as the 1st line of function)
memory usage = 597MB
As it exits the DataReady.m function (i.e., "memory" command as the last line of function)
memory usage = 545MB
DataReader.SGetDataEx(StartSample,NumberofSamples)
memory (i.e., "memory" command after datareader line)
So, it has leaked 545MB - 518MB = 27MB per data retrieval cycle. I think I might have mentioned it before, but using "clear" will not reduce the memory that Matlab holds up, as opposed to, say:
memory usage = 900MB
x = randn(10000,10000);
clear
memory usage = 100MB
Yes, your suggestion of using another client is an excellent idea, although I am not much of a programmer (only a little C programming from undergraduate studies, which I have forgotten). I don't know what MFC is. Will look into your suggestion.
Thanks,
Alan
|
|
|
|
|
Hi to all,
I am creating a IE toolbar in C#, using Band Object.
I want to get event or any attribute value, which show that is my toolbar is enable/disable in IE.Or which event/attribute of band object tell me the satus of my toolbar.
Please Help me.
|
|
|
|
|
Only way I know is to check registry key
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Ext\Settings\<GUID>, where <GUID> is your toolbar CLSID. If value 'Flags' exists in this key, then your toolbar is disabled. If Flags value does not exists or whole key does not exists - your toolbar is enabled.
|
|
|
|
|
hello
this is shikha, i m new in programming in Com Port, Actually my previous i did one project in which i have to receive/send SMS using COM1,
now the Device changed and it is supporting the Com3, Sending is working perfectly but unable to recive SMS using Port3.. here i m using Third party DLL. GSMCOMM DLL..just i m struck here,
one event is there "GsmComm.GsmCommunication.MessageReceivedEventArgs" is not firing, it should fired when message is recive BY the Port 3.. i m just unable to understand how to reslove the problem, i tried a lot, searched a lot....
<code> public partial class Receive : Form
{
private DataTable dt = new DataTable();
private delegate void SetTextCallback(string text);
System.IO.Ports.SerialPort port = new System.IO.Ports.SerialPort();
public Receive()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
//string storage = GetMessageStorage();
string storage = PhoneStorageType.Sim;
try
{
// Read all SMS messages from the storage
DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.All, storage);
foreach (DecodedShortMessage message in messages)
{
Output(string.Format("Message status = {0}, Location = {1}/{2}",
StatusToString(message.Status), message.Storage, message.Index));
ShowMessage123(message.Data);
Output("");
}
Output(string.Format("{0,9} messages read.", messages.Length.ToString()));
Output("");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Cursor.Current = Cursors.Default;
}
private void BindGrid(SmsPdu pdu)
{
DataRow dr = dt.NewRow();
SmsDeliverPdu data = (SmsDeliverPdu)pdu;
dr[0] = data.OriginatingAddress.ToString();
dr[1] = data.SCTimestamp.ToString();
dr[2] = data.UserDataText;
//dr[1] = data.UserDataText;
dt.Rows.Add(dr);
//Thread.Sleep(500);
dataGrid1.DataSource = dt;
}
SmsDeliverPdu data;
private void ShowMessage(SmsPdu pdu)
{
if (pdu is SmsSubmitPdu)
{
// Stored (sent/unsent) message
SmsSubmitPdu data = (SmsSubmitPdu)pdu;
Output("SENT/UNSENT MESSAGE");
Output("Recipient: " + data.DestinationAddress);
Output("Message text: " + data.UserDataText);
Output("-------------------------------------------------------------------");
return;
}
if (pdu is SmsDeliverPdu)
{
// Received message
data = (SmsDeliverPdu)pdu;
Output("RECEIVED MESSAGE");
Output("Sender: " + data.OriginatingAddress);
Output("Sent: " + data.SCTimestamp.ToString());
Output("Message text: " + data.UserDataText);
Output("-------------------------------------------------------------------");
//BindGrid(pdu);
return;
}
if (pdu is SmsStatusReportPdu)
{
// Status report
SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
Output("STATUS REPORT");
Output("Recipient: " + data.RecipientAddress);
Output("Status: " + data.Status.ToString());
Output("Timestamp: " + data.DischargeTime.ToString());
Output("Message ref: " + data.MessageReference.ToString());
Output("-------------------------------------------------------------------");
return;
}
Output("Unknown message type: " + pdu.GetType().ToString());
}
private void ShowMessage123(SmsPdu pdu)
{
if (pdu is SmsSubmitPdu)
{
// Stored (sent/unsent) message
SmsSubmitPdu data = (SmsSubmitPdu)pdu;
Output("SENT/UNSENT MESSAGE");
Output("Recipient: " + data.DestinationAddress);
Output("Message text: " + data.UserDataText);
Output("-------------------------------------------------------------------");
return;
}
if (pdu is SmsDeliverPdu)
{
// Received message
data = (SmsDeliverPdu)pdu;
Output("RECEIVED MESSAGE");
Output("Sender: " + data.OriginatingAddress);
Output("Sent: " + data.SCTimestamp.ToString());
Output("Message text: " + data.UserDataText);
Output("-------------------------------------------------------------------");
BindGrid(pdu);
return;
}
if (pdu is SmsStatusReportPdu)
{
// Status report
SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
Output("STATUS REPORT");
Output("Recipient: " + data.RecipientAddress);
Output("Status: " + data.Status.ToString());
Output("Timestamp: " + data.DischargeTime.ToString());
Output("Message ref: " + data.MessageReference.ToString());
Output("-------------------------------------------------------------------");
return;
}
Output("Unknown message type: " + pdu.GetType().ToString());
}
private string StatusToString(PhoneMessageStatus status)
{
// Map a message status to a string
string ret;
switch (status)
{
case PhoneMessageStatus.All:
ret = "All";
break;
case PhoneMessageStatus.ReceivedRead:
ret = "Read";
break;
case PhoneMessageStatus.ReceivedUnread:
ret = "Unread";
break;
case PhoneMessageStatus.StoredSent:
ret = "Sent";
break;
case PhoneMessageStatus.StoredUnsent:
ret = "Unsent";
break;
default:
ret = "Unknown (" + status.ToString() + ")";
break;
}
return ret;
}
private void Output(string text)
{
if (this.txtOutput.InvokeRequired)
{
SetTextCallback stc = new SetTextCallback(Output);
this.Invoke(stc, new object[] { text });
}
else
{
txtOutput.AppendText(text);
txtOutput.AppendText("\r\n");
}
}
private void Receive_Load(object sender, EventArgs e)
{
//Prompt user for connection settings
int port = 3 ;
int baudRate = 9600; // We Set 9600 as our Default Baud Rate
int timeout = 300;
//string Parity = "None";
//int DataBits = 8;
//int StopBits = 1;
TestConnection dlg = new TestConnection();
//frmConnection dlg = new frmConnection();
dlg.StartPosition = FormStartPosition.CenterScreen;
//dlg.SetData(port, baudRate, timeout,Parity,DataBits,StopBits);
dlg.SetData(port, baudRate, timeout);
if (dlg.ShowDialog(this) == DialogResult.OK)
{
dlg.GetData(out port, out baudRate, out timeout);
//dlg.GetData(out port, out baudRate, out timeout, out Parity, out DataBits, out StopBits);
CommSetting.Comm_Port = port;
CommSetting.Comm_BaudRate = baudRate;
CommSetting.Comm_TimeOut = timeout;
//CommSetting.Comm_Parity = Parity;
//CommSetting.Comm_DataBits = DataBits;
//CommSetting.Comm_StopBits = StopBits;
}
else
{
//Close();
return;
}
Cursor.Current = Cursors.WaitCursor;
CommSetting.comm = new GsmCommMain(port, baudRate, timeout);
Cursor.Current = Cursors.Default;
CommSetting.comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);
bool retry;
do
{
retry = false;
try
{
Cursor.Current = Cursors.WaitCursor;
CommSetting.comm.Open();
Cursor.Current = Cursors.Default;
}
catch (Exception)
{
Cursor.Current = Cursors.Default;
if (MessageBox.Show(this, "Unable to open the port.", "Error",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry)
retry = true;
else
{
Close();
return;
}
}
}
while (retry);
//Prompt user for connection settings
dt.Columns.Add("Number", typeof(string));
dt.Columns.Add("Time", typeof(string));
dt.Columns.Add("Message", typeof(string));
}
private void comm_MessageReceived(object sender, GsmComm.GsmCommunication.MessageReceivedEventArgs e)
{
MessageReceived();
}
bool _flagNumber;
bool _FlagName;
int i;
private void MessageReceived()
{
Cursor.Current = Cursors.WaitCursor;
string storage = PhoneStorageType.Sim;
int port = 3;
int baudRate = 9600;
int timeout = GsmCommMain.DefaultTimeout;
// string Parity = "None";
//int DataBits = 8;
//int StopBits = 1;
TestConnection dlg = new TestConnection();
//frmConnection dlg = new frmConnection();
dlg.StartPosition = FormStartPosition.CenterScreen;
dlg.SetData(port, baudRate, timeout);
dlg.GetData(out port, out baudRate, out timeout);
//dlg.SetData(port, baudRate, timeout, Parity, DataBits, StopBits);
//dlg.GetData(out port, out baudRate, out timeout, out Parity, out DataBits, out StopBits);
CommSetting.Comm_Port = port;
CommSetting.Comm_BaudRate = baudRate;
CommSetting.Comm_TimeOut = timeout;
DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, storage);
foreach (DecodedShortMessage message in messages)
{
Output(string.Format("Message status = {0}, Location = {1}/{2}",
StatusToString(message.Status), message.Storage, message.Index));
ShowMessage(message.Data);
Output("");
SMS si = new SMS();
SmsBL SmsBal = new SmsBL();
si.OrderDateTime = data.SCTimestamp.ToDateTime().ToShortDateString();
si.OrderFrom = data.OriginatingAddress;
si.OrderMsg = data.UserDataText;
si.ReadStatus = "Read";
si.OrderStatus = "Active";
SmsBal.InsertSMSDetails(si);
SMS sms1 = new SMS();
SmsBL smsbal = new SmsBL();
//sms1.Number = data.OriginatingAddress.ToString();
//string _strMessage = smsbal.InsertNumber(si);
SmsSubmitPdu AutoSend = new SmsSubmitPdu();
try
{
DataTable dt = new DataTable();
dt = smsbal.GetNumber();
DataTable dt1 = new DataTable();
dt1 = smsbal.GetDealer();
for ( i=0; i<=dt.Rows.Count-1;i++)
{
if (dt.Rows[i].ItemArray[0].ToString() == data.OriginatingAddress.ToString())
{
_flagNumber = true;
}
}
if (_flagNumber)
{
for (int j = 0; j <= dt1.Rows.Count - 1; j++)
{
string name=dt1.Rows[j].ItemArray[1].ToString();
if (name.ToUpper()== data.UserDataText.ToUpper())
{
_FlagName = true;
AutoSend = new SmsSubmitPdu( "Transaction Amount is:"+dt1.Rows[j].ItemArray[4].ToString(), data.OriginatingAddress, string.Empty);
CommSetting.comm.SendMessage(AutoSend);
}
}
}
else
{
MessageBox.Show("SMS Not Registered");
}
if (!_FlagName)
{
MessageBox.Show("Invaild SMS","Read Message",MessageBoxButtons.OK,MessageBoxIcon.Information );
//AutoSend = new SmsSubmitPdu(dt1.Rows[i].ItemArray[4].ToString(), data.OriginatingAddress, string.Empty);
//CommSetting.comm.SendMessage(AutoSend);
}
//else
//{
// MessageBox.Show("Invaild SMS");
//}
}
catch (Exception ex)
{
Output(ex.Message);
}
}
Output(string.Format("{0,9} messages read.", messages.Length.ToString()));
Output("");
}
private void Output(string text, params object[] args)
{
string msg = string.Format(text, args);
Output(msg);
}
private void button1_Click_1(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
//string storage = GetMessageStorage();
string storage = PhoneStorageType.Sim;
try
{
// Read all SMS messages from the storage
DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.All, storage);
foreach (DecodedShortMessage message in messages)
{
Output(string.Format("Message status = {0}, Location = {1}/{2}",
StatusToString(message.Status), message.Storage, message.Index));
ShowMessage123(message.Data);
Output("");
}
Output(string.Format("{0,9} messages read.", messages.Length.ToString()));
Output("");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Cursor.Current = Cursors.Default;
}
private void Receive_FormClosing(object sender, FormClosingEventArgs e)
{
// Clean up comm object
if (CommSetting.comm != null)
{
// Unregister events
///CommSetting.comm.PhoneConnected -= new EventHandler(comm_PhoneConnected);
CommSetting.comm.MessageReceived -= new MessageReceivedEventHandler(comm_MessageReceived);
// Close connection to phone
if (CommSetting.comm != null && CommSetting.comm.IsOpen())
CommSetting.comm.Close();
CommSetting.comm = null;
}
}
}
} </code>
plzzzzzz help me!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Shikha,
your post is so wonderfully misplaced I just cannot refrain from answering....
1. Wrong forum
This forum is about COM, as in Component Object Model[^], and not about COMmunication ports.
2. Wrong forum #2
Even if this forum was dedicated to COMmunication ports, your post isn't really about how to use the COM port for reading and writing; your post is about a third party DLL that perhaps someone has used, but don't count on it. You' d probably be better off asking the "third party" why your application, and/or the DLL, misbehaves.
If it was really about COM ports, you should have a look at this excellent article[^].
Even though you seem to use C#, which I'm not familiar with, the Win32 API calls mentioned in the article is still the same as well as the concept of "how to do serial port programming".
3. Debug your application
Prior to posting a lot of code that you hope someone will debug (for free) and pinpoint what you have done wrong, you should debug it yourself. It would increase your skills, you'd get to know your own code and why it behaves the way it does. It may come to a point where you expect a certain behaviour that you don't experience, get stuck and start posting questions in forums like this one. But the explanation of the problem has to be more detailed than "it doesn't work, here's the code, please help me".
4. Use code formatting tags
The code you've posted is very hard to read.
It looks like you've tried to format the code you've posted, but you've probably checked the "Do not interpret HTML tags..." checkbox below the text input box when writing your post.
Tip of the day: preview your post before you send it.
Your post has been down voted for the above reasons.
It wasn't by me, but it could have been.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I need a help regarding OLE objects instantiaton and termination.
I have a trial application which uses a dll which uses global instances of OLE pointers of an application as given below
FMApplication *fmApp = NULL;
FMCase *fmCase = NULL;
CoInitialize is called during DLL_PROCESS_ATTACH and the above OLE objects are instantiated henceforth. However, on exit of the application, the process hangs saying issue with OLE pointers. I tried releasing OLE instance in DLL_PROCESS_DETACH. Somehow OLE instances could not release and hangs there. I have ensured CoUninitialize is not called anywhere before OLE instance Release.
fmApp->Release(); //Fails here
fmApp = NULL;
fmCase->Release();
fmCase = NULL;
|
|
|
|
|
Do you know this (MSDN [^])
Because there is no way to control the order in which in-process servers are loaded or unloaded, do not call CoInitialize, CoInitializeEx, or CoUninitialize from the DllMain function.
?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
To expand on CPallini's ansawer - here's Larry Osterman and Raymond Chen[^] on the subject - and they are two Windows guys who should know the real deal!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
hi,
can any body tell how can i add .dll for my application(c#.net) because it can not directly added from add references( neither .net nor from com component)
so i want to add dll through command prompt
i edit c:\>regsvr "c:\BAS\bin\Deug\BAS_DAL.dll"
BUT IT PRODUCE MESSAGE
" C:\BAS\bin\Deug\BAS_DAL.dll was loaded but the DllRegisterServer entry point was noy found, DllRegisterServer may not be exported "
HOW CAN ADD I .dll to my project through command prompt or Other way
from :-Jaydeep Bhatt
|
|
|
|
|
If you wrote the DLL in (say) C++, then you probably need to use PInvoke - here's an introduction[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi,
If your dll has .Net framework dependency then try the following,
Go to .Net command prompt and enter the command below,
RegAsm yourDll.dll /tlb:yourDll.tlb /codebase
Note: It will register in to GAC & export tlb.
Thanks
Md. Marufuzzaman
|
|
|
|
|