|
Hi,
It all depends. What API?
.NET supports dynamic stuff but it is not simple to use it.
If the number of required types is limited (say a subset of the Win32 types) it would be much easier
to predefine those types, that is what everyone is doing when calling native functions from
kernel32.dll, user32.dll, and the like. As an example, look at www.pinvoke.org
If the types are yours, and you are in charge of the code on both sides, then you may consider replacing all those structs by key-value collections, where both keys and values are strings. As far as the interface goes, that could boil down to an array of strings (holding an even number of them),
or even one big string with a separator char as in
"key1=value1;key2=value2;...;keyN=valueN"
Hope this helps.
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
|
|
|
|
|
Luc Pattyn wrote: It all depends. What API?
So far the requirement is Win32 API
Luc Pattyn wrote: www.pinvoke.org
This site is down?
Luc Pattyn wrote: consider replacing all those structs by key-value collections, where both keys and values are strings
I had test all what you said except array.
The String with "," works fine with me
Yup, It was very helpful
Thanks
Samir R. Ibrahim
|
|
|
|
|
Sorry, it is PInvoke.net[^]
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
|
|
|
|
|
Hello friends,
I am struck with a bug in my code and find it difficult to debug.
In my MS access application, I am creating some reports using SQL queries to fetch data from Access Table and SQL table. Some time the code works fine, creating the report fine. Some time its not creating the report fully, skipping some queries and conditions.
If I try to run the code using 'Step in', the report always creating as expected. if it run otherwise report fails. I tried using with delays, then its working fine. But I have to use min 5 sec delay for that. So its effecting the performance.
I dont have much experience in VBA and SQL queries. IS it due to some error in my code or something else?
Thanks and regards
Jishith
|
|
|
|
|
Without seeing the code, it's impossible to say. Even then, with it may be difficult. If sections of code are being skipped, it sounds like you have a design problem or you're catching and eating errors with On Error Resumt Next, without checking the Err object at various stages to see if an error occured before continuing.
|
|
|
|
|
The code works always fine with single steppings. When at full running , the problem occurs.. If i putting any break point inside the code, 80% times run properly...
And i am not using On Error Resume Next in this function.
|
|
|
|
|
Then you're going to have to put some tracing code in there to see what variables have what values at various points in your code. Log this information to a file and review it when the problem occurs.
|
|
|
|
|
Hi All,
I am working in a project "send and receive message using PC/mobile(GSM)". Sending and receiving messages are working properly. But while reading/sending messages, If any interruption(like SMS/CALL) comes to mobile, my process has to be stopped/waiting long time for network answer/returns "+CMS:Error".
I have changed my code that one thread do sending messages and another thread will do read messages. So I used backgrounworker thread for sending messages. But it also doesn't works.
still am getting same error(stopped/waiting long time/returns "+CMS:Error").
Give some idea to do this correctly..... send related links to read
Thanks in Advance
modified on Saturday, February 14, 2009 1:13 AM
|
|
|
|
|
So you're saying that your app is completely halted during a call?? OK, if every thread in your app is halted, there's nothing you can do about that. All you can do is handle the error and retry the send. Reading is out of your hands because the sender doesn't know what happened and just gave up. Apparently...
|
|
|
|
|
Yes. If any call has come during sending SMS, it will stop few seconds to send a message and automatically start to send SMS. So,timing variations also arised. That particular sms only takes morethan 20 seconds to reach destination.
Because of that only i have to tune the timings of the sending SMS. Give some idea...
|
|
|
|
|
You have to "tune the timing" of sending an SMS?? I've never heard of anyone ever having to do that. It sounds like you have a serious design flaw in your app.
|
|
|
|
|
I am having trouble getting my head around a Threading problem I have. I want to process some data while displaying a message stating that the data is being processed.
So hear is some sample code that I have been trying.
thrd = New Thread(AddressOf ThreadProc)
thrd.start()
'process data
thrd.abort 'I want a way to know when process data is done.
Private Sub ThreadProc()
Dim load As New Loading
load.ShowDialog()
End Sub
But, When my process is done the showdialog does not go away until I click in the form or move the mouse. Any suggestions on how to do this. How can I get the showdialog to go away?
|
|
|
|
|
Hi Cory,
this is so wrong.
It is almost always a bad idea to abort a thread since you typically don't know what it is doing at that specific point in time, and resources may be locked, memory allocated, etc.
In this particular case, aborting the thread stops the message pump that was keeping the
progress dialog alive (the pump is a loop running inside the ShowDialog method); by aborting the thread, the dialog just sits there, completely dead, what piece of code would be responsible of removing it?
The correct way to handle this is by:
1. putting the time-consuming stuff in a thread or a BackgroundWorker (BGW are available since .NET 2.0), which you want to run to completion, hence no abort necessary;
2. showing the progress dialog in the normal manner, without using an extra thread.
3. letting the thread/BGW signal the progress dialog when it is done (this obviously requires caution about cross-thread violations, automatically solved by BGW, and solvable with Control.InvokeRequired/Control.Invoke on regular threads.
4. you may add real progress indication in the dialog; again a BGW is helping there
5. you may want to add a Cancel button; the proper way to handle a cancel request is by having the background job done in a collaborative way, typically by periodically checking a "please cancel" flag. Don't use Thread.Abort if you don't have to!
I strongly suggest you study some BackgroundWorker examples.
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
|
|
|
|
|
Hi,
I am experiencing a difficulty to use one the reference (dll) file inside the code page. It is listed under References and also it shows up under the references section in the property page of the project. However when I use Imports .... I was expecting to see its name. Neither I am able to call its name with imports nor I am able to use it explicitly with Dim ax as New ResourceName.
Do you have any idea why? I am using VS2008
Thanks.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
Double click that dll from references and it will open up in Object Browser. Now see are you using the correct namespace or not.
|
|
|
|
|
I am confused on how to extend a generic type like the KeyValuePair(of TKey, TValue). For example, I want to override the .tostring method, but am confused on what to inherit from to accomplish this.
Could someone nudge me in the right direction?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
You can inherit two ways depending on how specific your requirements are. Either:
MyGenericKeyValuePair(Of TKey, TValue)
Inherits KeyValuePair(Of TKey, TValue)
or
MyKeyValuePair
Inherits KeyValuePair(Of String, Integer)
If you have only one type of KeyValuePair for which you want to overwrite ToString, option 2 is best.
|
|
|
|
|
Hey Gideon,
Thanks for the response. I def. need method #1 (Of TKey, TValue). When I try this:
Public Class KeyValuePair_Generic(Of TKey, TValue)
Inherits KeyValuePair(Of TKey, TValue)
End Class
I get "Classes can only inherit from other classes."
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
KeyValuePair(Of TKey, TValue) is not a Class but rather a Structure (struct) which means you can't inherit from it. You would need to create your own equivalent Structure (and I would recommend using a Structure rather than a class) and using that instead.
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Roger that. I'll give that a go.
Thanks.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I looked in the code behind file but I don't see any code for adding event handlers for controls such as: AddHandler ..., Addressof....
How is this possible if the event handler does not even have the Handles xxx.event at the end of the event handler?
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
Did you notice the "WithEvents" clause on those Dim statements?? Did you also notice the "Handles" clause on the end of the event handler headers?? Read this[^] and you'll know how it works.
Dim WithEvents someVariable As New Button
.
.
.
Private Sub ButtonClickHander(..., ...) Handles someVariable.Click
|
|
|
|
|
All this inconsistency between C# and VB.NET makes things more confusing. It has never helped me.
CodingYoshi
Visual Basic is for basic people, C# is for sharp people. Farid Tarin '07
|
|
|
|
|
That's starting to change...
|
|
|
|
|
Hello, all.
Is it possible to get the name of a local variable from a reference to the variable? For example, I can get the names and values of a calling function's parameters like this:
Dim frame As New StackFrame(1)
Dim pInfos() As ParameterInfo = frame.GetMethod().GetParameters()
Is there some way to get the same information for a calling function's local variables? This is kind of what I have in mind:
Sub SomeSub()
Dim count As Integer = 10
Dim average As Single = 45.67
LogLocalVariables(count, average)
End Sub
Sub LogLocalVariables(ByVal var1 As Object, ByVal var2 As Object)
' I can get each variable's type like this:
Dim mBody As MethodBody = GetType(Form1).GetMethod _
("SomeSub").GetMethodBody()
Dim varList As ObjectModel.ReadOnlyCollection(Of LocalVariableInfo) = _
mBody.LocalVariables
' But what I really want is info like this:
' count = 10
' average = 45.67
End Sub
Thanks.
--Clay
|
|
|
|