|
The real question is why you would do this. I've been writing code for 23 years and never have had the need to do so.
|
|
|
|
|
I am special case that you HAVE to deal with.
btw: I did not start asking hard question yet
As you said twice, and as I confirm twice, I don't have a problem which I want to solve.
Asking "Why" is good question, because it may eliminate the need.
I learn something from you and Luc, the "Thinking/Technique" itself to solve a problem in VB.Net is totally different from thinking when creating in VFP. And I thought I will face trouble just in finding the right language command changing.
Each language has it is limit and capabilities, and I am discovering vb.net possibilities.
I can solve my problem by simple declare all the TYPES I want in a single module and return the TYPE I need by sending the TYPE name as parameter.
I don't know if VB.Net support the creation of FLAT dll. where I can declare a function in a FLAT dll i create as I declare win32 API Function and send the TYPE to it without the need of create a TYPE as constant.
I am organized in my programming approach, I had 1 month started with VB.Net and I am already collecting vb.net code and API not just save them as html in a folder, I am creating a classes in order to make the working with any project more easier.
My next approach after butting the code I collect in a class, is to learn how to create FLAT dll, not COM dll. If I will face a trouble in creating FLAT dll, I will simply go to COM DLL.
That is the real reason why I am asking this question.
The Second reason, is the ability to create DLL(FLAT or COM) created by vb.net and use it in VFP if possible. since VFP does not support TYPE or Construct I would like to know if that is possible.
Thank you for your time and attention regarding my question.
Samir R. Ibrahim
|
|
|
|
|
First, the FLAT dll you're talking about is really a Library DLL. There are two types - normal and .NET. A .NET library DLL is not usable by Win32 functions as is because the managed code compilers in .NET don't support the proper exports required by Win32.
Samir Ibrahim wrote: I can solve my problem by simple declare all the TYPES I want in a single module and return the TYPE I need by sending the TYPE name as parameter.
Bad idea. You normally organize the data model in individual classes or groups of classes that deal with specific parts of your data model. The concept is called encapsulation. You don't put everything in a single module and then tell some creator which type you want. Though that has its uses, it's called the Factory pattern, the way you describe it, you're violating OOP rules.
Samir Ibrahim wrote: The Second reason, is the ability to create DLL(FLAT or COM) created by vb.net and use it in VFP if possible.
It's possible, but not as a library DLL. VB.NET and C# don't support the old Win32 exports you're inferring. You have to attribute the classes you want to expose properly so they're exposed through COM.
|
|
|
|
|
Dave Kreskowiak wrote: The concept is called encapsulation.
That concept is one of the reason of me taking 4 kind of medicine
I had gone through a lot of discussion regarding encapsulation in OOP rule. And I read to much about it. I hope that you don't mind I ask you about this later on.
Dave Kreskowiak wrote: you're violating OOP rules
That is a big assumption to say it so early before you see the code.
As saying "Public variable will break the Encapsulation", which is totally wrong if you mean it as abstract sentence.
Dave Kreskowiak wrote: It's possible, but not as a library DLL. VB.NET and C# don't support the old Win32 exports you're inferring.
Thank you for the information.
I learn new thing from you with every post
Samir R. Ibrahim
|
|
|
|
|
Hi again
It seem I miss-understand your question.
The point is, create a structure on the fly that can be passed to API calls when the API needs TYPE declaration.
Samir R. Ibrahim
|
|
|
|
|
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
|
|
|
|
|