|
Using timers in C/C++ (upon which MFC is written) to distinguish between clicks and double clicks is the most common scenario as well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks a lot....
I could solve the problem
Sandeep Naik
|
|
|
|
|
Hi,
I'm trying to write a class which provides access to several collections. Business requires, that the user of my class might access the collections content (the objects stored in it) without allowing him to modify the collection itself, that is, he can enumerate the objects, access call methods / access properties, but can't add or remove objects to or from the collection.
I hope I got the question clear enough to understand
What is the best way of designing this?
Thanks in advance!
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
|
|
|
|
|
Extend whatever IList implementation you want (or just implement it yourself, or extend CollectionBase ) and override IsReadOnly . Define a method that sets a state variable and can never set it again like so:
public class ReadOnlyArrayList
{
bool readOnly;
public override bool IsReadOnly
{
get { return readOnly; }
}
internal void SetReadOnly()
{
readOnly = true;
}
} And there you go. Once you've filled it with the objects you want in the list, call SetReadOnly . ArrayList , along with other IList implementations in the BCL, check IsReadOnly before allowing changes using methods like Add or Remove . If you implement IList yourself, make sure you do the same.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
If you have methods returning ArrayList and you don't want the consumer of the list to modify it, you can use ArrayList.ReadOnly(collection) method.
For example if you have internal:
ArrayList myList;
and method returning this list:
ArrayList GetMyList()
{
return ArrayList.ReadOnly(myList);
}
that way they will get ArrayList with all elements of your list. However if you internally change content of the list inside your class, then those changes will be reflected in the returned list (if someone is pointing reference to it).
Hope this makes sense.
|
|
|
|
|
I am handling OnClik and OnDoubleClick event on a listView. When ever user doubleclicks on a item, first OnClick and then OnDoubleClick event gets fired. Is there a way to avoid OnClick event when user has DoubleClicked on the item ?
Sandeep Naik
|
|
|
|
|
1. my vendor interface is defined in an h & c file:
_EXTERN S16BIT _DECL aceSetIrqConditions(S16BIT DevNum, U16BIT bEnable,
U32BIT dwIrqMask,void(_DECL *funcExternalIsr)(S16BIT DevNum, U32BIT
dwIrqStatus))
void _DECL Callback(S16BIT DevNum, U32BIT dwIrqStatus);
/* Configure user callback ISR and enable EOM interrupts */
aceSetIrqConditions(DevNum, TRUE, ACE_IMR1_BC_MSG_EOM, Callback);
void _DECL Callback(S16BIT DevNum, U32BIT dwIrqStatus)
{
/* this is what I would write, I would like to get here with C#
}
2. I am trying to use the vendor interface for the above
aceSetIrqConditions() to call an interrup routine I write (eomInterrupt).
This is my C# effort, it compiles, but when I try to execute this, I get an
Error, see below:
// EOM Interrupt declaration
public delegate void Callback(short DevNum, uint dwIrqStatus);
[DllImport("C:\\acs\\bin\\Release\\emace_32.dll")]
public extern static short aceSetIrqConditions(short DevNum, ushort bEnable,
uint dwIrqMask, Callback cbm);
Callback cbm = new Callback(eomInterrupt);
aceSetIrqConditions(devNum, 1, ACS1553.ACE_IMR1_BC_MSG_EOM, cbm);
public void eomInterrupt(short DevNum, uint dwIrqStatus)
{
/* *** never gets to statement below! *** */
if((dwIrqStatus & ACS1553.ACE_IMR1_BC_MSG_EOM) != 0)
{
irqCount++;
}
}
The error is:
Debug Error!
File:i386\chkesp.c, Line 42.
The value of ESP was not properly saved across a function call. This is
usually a result of calling a function declared with one calling convention
with a function pointer declared with a different calling convention.
The program runs fine, except when I added above. What am I doing wrong???
Thanks,
--
Evelyne
Expand AllCollapse All
Evelyne S. Mitchell
|
|
|
|
|
First, if possible NEVER hard-code the path to the DLL from which you want ot P/Invoke functions. If necessary, add the path to the PATH environment variable and restart the application. If you hard-code the path, you're only in for a world of maintanance nightmares.
Also, if you haven't already read Consuming Unmanaged DLL Functions[^] and Marshaling Data with Platform Invoke[^], but you seem to have a good grasp of P/Invoke.
As far as the calling convention problem, we have discussed this before and it is a known problem. To better help you, though, what exactly is _DECL defined as?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath, Thanks for answering.
Why did my first reply not appear on the message board?
I don't know what _DECL is defined as.
Here are some applicable snippets from the vendor example, coded in c:
#ifdef WIN32 #include #include "stdemace.h" #include #endif
...
void _DECL Callback(S16BIT DevNum, U32BIT dwIrqStatus);
...
/* somewhere in their main, the conditions to call the user interrupt routine are set up */
/* Configure user callback ISR and enable EOM interrupts */ aceSetIrqConditions(DevNum, TRUE, ACE_IMR1_BC_MSG_EOM, Callback);
...
/* this is what I would write in C# */
/* can I define a C# method by assigning a calling convention of Cdecl? How do I do that? Where do I put the statement CallingConvention=CallingConvention.Cdecl? By the way this is just an idea!?! */
void _DECL Callback(S16BIT DevNum, U32BIT dwIrqStatus)
{
/* confirm that IRQ is ACE_IMR1_BC_MSG_EOM */
if(dwIrqStatus & ACE_IMR1_BC_MSG_EOM )
{
nNumIrqcounter++;
// todo: perform additional message processing
}
}
I hope this helps?
Evelyne S. Mitchell
|
|
|
|
|
Evelyne wrote:
Why did my first reply not appear on the message board?
You hit the "Email" link instead of "Reply".
It's important to know what _DECL is defined as because that's obviously defining your calling convention.
You could just assume it uses the __cdecl calling convention and add the CallingConvention.Cdecl to your DllImportAttribute :
[DllImport("emace_32.dll", CallingConvention=CallingConvention.Cdecl)]
static extern short aceSetIrqConditions(short DevNum, ushort bEnable,
uint dwIrqMask, Callback funcExternalIsr);
delegate void Callback(short DevNum, uint dwIrqStatus); Unfortunately, that won't solve your immediate problem. Delegates use the __stdcall calling convention and you can't change this directly in C#. You have to do one of the follow:- Change your native DLL to use the
__stdcall calling convention (probably can't since this sounds like it's from another vendor) - Write a Managed C++ assembly that wraps this functionality. Since it targets the CLR and follows the CLI (mostly) you can use it in other managed languages like C#, VB.NET, etc.
- Disassemble our assembly, change the calling convention, and reassemble your assembly.
For the last one, write your code and compile your project. Run ildasm.exe <MyProject.exe> to disassemble it. Find the declaration of your callback and add the following between the return type and the name Invoke defined for the delegate:
modopt([mscorlib]System.Runtime.CompilerServices.CallConvCdecl) Now reassemble using ilasm.exe (notice no "d"). You will want to read about this tool in the .NET Framework SDK before running it to make sure your assembly gets resigned correctly, and you really should sign your assemblies (and version them) to produce a strong name assembly. Not doing that leads to security problems and makes upgrades and .NET code access security a pain. Frankly, it's easy. Just run sn.exe -k <filename> to generate a key pair and set the path in your AssemblyInfo.cs (by default using VS.NET) file's [assembly: AssemblyKeyFile("")] attribute, or add it to a container using sn.exe -i and use the AssemblyKeyNameAttribute instead.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath,
I tried to take your option 1 first, sounded less complicated. So I contacted the vendor and here is what they said:"The calling convention of the callback routine for the user interrupt is not _cdecl. The callback is defined to be _DECL which we have #defined in our code to be WINAPI. In the Windows files WINAPI is defined to be the standard calling convention. From Windef.h which is a Windows header file: #define WINAPI __stdcall."
So by not defining the calling option of CallingConvention=CallingConvention.Cdecl, that should have worked to begin with? So what do I doe now, I am really confused???
Evelyne S. Mitchell
|
|
|
|
|
Thought I would update you. I was out of commission over the weekend because of Hurricane Jeanne, no power, no work on Monday.
I have changed my code to the following (yes, I still have the absolute path in here!) and I do get to my interrupt routine now:
public delegate void Callback(short DevNum, uint dwIrqStatus);
public static Callback cbm = new Callback(eomInterrupt);
[DllImport("C:\\acs\\bin\\Release\\emace_32.dll",CallingConvention=CallingConvention.StdCall)]
public static extern short aceSetIrqConditions(short DevNum, ushort bEnable, uint dwIrqMask, Callback cbm);
public static void eomInterrupt(short DevNum, uint dwIrqStatus)
{
/* confirm that IRQ is ACE_IMR1_BC_MSG_EOM */
if((dwIrqStatus & ACS1553.ACE_IMR1_BC_MSG_EOM) != 0)
{
irqCount++;
}
}
Thanks for your help,
Evelyne S. Mitchell
|
|
|
|
|
Hi,
I have a problem, I want to check a data is entered to SQL database or not. I am making this in PHP like below:
<br />
$sql_name_check = mysql_query("SELECT name FROM names WHERE name='$buffer_name'");<br />
if(!mysql_num_rows($sql_name_check)){<br />
}<br />
So I want to do that in C# so I made a code block which is below:
<br />
int k=0;<br />
string buffer_name = "Cem Louis";<br />
SqlConnection mySqlConnection = new SqlConnection("Initial Catalog=names;Data Source=localhost;Integrated Security=SSPI;");<br />
SqlCommand mySqlCommand = mySqlConnection.CreateCommand();<br />
mySqlCommand.CommandText = "SELECT name, tel FROM names WHERE tel = '1' AND name = name";<br />
mySqlConnection.Open();<br />
SqlDataReader mySqlDataReader3 = mySqlCommand.ExecuteReader();<br />
while(mySqlDataReader3.Read())<br />
{<br />
k++;<br />
}<br />
if(k > 0)<br />
return false;<br />
else<br />
return true;<br />
mySqlDataReader3.Close();<br />
mySqlConnection.Close();<br />
Thank you;
Cem Louis...
|
|
|
|
|
|
And my question is:
How can I know that the SQL query returns a result? Is the cell filled with data??? The C# code that I wrote above is not doing this with variable k++ increment...
Thanks...
|
|
|
|
|
If you have any rows returned SqlDataReader has property HasRows
SO you can do:
if (reader.HasRows)
{
// something returned
}
|
|
|
|
|
hmm HasRows...
Thank you...
|
|
|
|
|
is there a way i can read a file that someone else has exclusive access to useing a streamreader
thanks
chad
|
|
|
|
|
No, not really. If they opened the file exclusively then it's opened, well, exclusively. It needs to be opened with FileShare.Read or some flag containing FileShare.Read in order for you to read it.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
the reson i am asking is because we have a csharp app that can read files while other users have the files exclusive and i would love to know how that programmer did it (its an app that we got from another company) and i know the files are exclusive because if i try to open then i get and error but this program dose not
thanks
chad
|
|
|
|
|
cmarmr wrote:
i would love to know how that programmer did it
One word: Reflector[^].
|
|
|
|
|
I need to detect when "windows + D" click or "show desktop" occurs. Which event occurs when this happenned?
karanba
|
|
|
|
|
The Windows message that is generated is not sent to every application, so you need to implement a Winodws hook. Read Using Hooks from C#[^] for more detail.
Specifically, you need to install a keyboard hook using WH_KEYBOARD (0x2). Your callback would be defined like so:
delegate IntPtr KeyboardProc(IntPtr code, IntPtr wParam, IntPtr lParam); The specific constants you want to check for are VK_LWIN (0x5b) and VK_RWIN (0x5c), as well as VK_D (0x44). Read KeyboardProc[^] for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Is it a proper to design the business logic layer & Data access layer as a web service in a n-tier application. What are the pros and cons of using this. when should i use it and when i should not. My UI may be a windows or web application does webservice affect it by any way.
Another Query:
What the typical functions required in dblibrary.?
How can i optimize database access in a dblibrary?
What are the things to be kept in mind when designing a dblibrary?
How can i make my dblibrary also database independent i.e. tommorow i should be able to change the database without changing code just change the configuration settings in some resource file)?
I am sorry if its unclear .
Thanks to all who has answered my previous queries.
Thanks in advance for any reply?
I would like hear the answer of these queries with reason ie. why something is better or not?
with regards
anand
|
|
|
|
|
It is typically dependent on the client’s wish. Some clients do not prefer to business logic sitting on the IIS machine and for Web Services you require the IIS machine. In such situation, the solution is to use .NET remoting to access services secured inside the firewall while your IIS Web Service sits outside the firewall in the DMZ and just serves requests.
The question you have raised is really important from the point of view of the *trust* users are going to put over IIS/.NET basde Web Services, while the recent IIS exploit memories are still fresh. I expect some interesting advice from the Microsoft guys and the pattern gurus.
Your database questions are irrelevant for this forum, please use the ADO forum. Lets me tackle the only forum relevant question:
Database independent programming: OBBC technology has been around for years to solve this problem. .NET has OLEDB and ODBC Adaptors, which you can read on and use to achieve the same purpose. The documentation clearly stating which one among these two is suited for which purpose, is a bit rare to find, but some experts will soon throw light on this. Lets wait a while…
|
|
|
|
|