|
That'l teech ya, have a code dump to play with. (see the reply to OG)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
uhh
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
And "dump" is the right word: a quick scan and "goto" leaps out at me.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello, dear forum.
I have a problem programming on C#. My recent activities with C++ are back over 20 years.
I downloaded from the internet a server/client-solution for SQLite and am stuck in my C#-application using this dll.
HRESULT hr;
HMODULE hMod = NULL;
PDLLGETCLASSOBJECT proc = NULL;
IClassFactory* pFactory = NULL;
hMod = GetModule( szDllPath );
if( !hMod ) return( false );
proc = (PDLLGETCLASSOBJECT) GetProcAddress( hMod, "DllGetClassObject" );
if( !proc ) return( false );
hr = proc( IInterface , IID_IClassFactory , (void**)&Factory );
if( hr || !pFactory ) return( false );
hr = pFactory->CreateInstance( NULL, IInterface , pInterface );
if( hr || !pInterface ) return( false );
pFactory->Release();
What I've done so far (not much):
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode]
private static extern IntPtr LoadLibrary(String lpFileName);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true)]
private static extern IntPtr GetProcAddress(IntPtr hModule, String procName);
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern Boolean FreeLibrary(IntPtr hModule);
...
private static String DLLFile = string.Empty;
private static IntPtr handleDLL = IntPtr.Zero;
private static IntPtr handleProc = IntPtr.Zero;
...
DLLFile = MyPath + @"Lib\SQLQueryAS.dll";
handleDLL = LoadLibrary(DLLFile);
if (handleDLL == IntPtr.Zero) throw new Win32Exception(Marshal.GetLastWin32Error());
handleProc = GetProcAddress(handleDLL, "DllGetClassObject");
if (handleProc == IntPtr.Zero) throw new Win32Exception(Marshal.GetLastWin32Error());
???
and now
???
Then (unless I have understood correctly) it should invite a class, so you can responsive in this class located methods (procs/functions).
Please help me. What should happen next?
Thank you in advance.
modified 2-Mar-16 17:05pm.
|
|
|
|
|
There is a .NET specific assembly available for download[^], which means you don't need C++.
You open a SQLiteConnection and issue a SQLiteCommand
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for answering.
My intention is a Server/Client solution, where the Server is on another remote machine than the Client. IMHO the System.Data.SQLite does not support this. Or am I totaly wrong with the mentioned dll?
|
|
|
|
|
This sounds a bit weird. If the server is on another machine, the client should "protect" you from the fact that you're dealing with a database.
If you want to use Sqlite (and connect to such a db) on a remote machine, I have never tried such a scenario, but seems to defeat the purpose of sqlite. In other words, the whole purpose of sqlite is to keep everything into a file which it can access really fast at any time. If that file is remote, that guarantee is gone.
Best,
John
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
John is correct, you are using the wrong tool for the job. Trying to use a single user, local database as a server database. Use a server database!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you for participating in my question.
Of course, you ALL are right with the (ab)use of SQLite for such a task.
But there are in the market some providers of such scenarios, unfortunately, to pay what separates for my hobby.
Therefore I've decided for this supplier, which is for free.
Please, let's go away from the theme SQLite, at all from the theme database.
My original question was how to reconstruct the functionality of a language (C++) in another language (C#).
To use a DLL with embedded class ...
Is there even any further help?
Thank you.
|
|
|
|
|
You should go back and read Eddy Vluggen's response. You do not need to reproduce anything from C++, you just need to use the .NET assembly that supports SQLite. If you then want to separate your database from your client application, you can use a socket connection between the two C# programs.
|
|
|
|
|
If you want to go that route, first off, it matters a lot if the functions you want to use are C functions, or C++ functions.
If they are C functions, you're in luck. Otherwise, each (member-)function will be really weirdly mangled by the compiler into and it will be really really painful to use.
Assuming we're in the C-functions area, you don't really need to complicate yourself with loading the library and such.
What I suggest is to bring the dll you need into a path that is auto-recognized by the OS - simplest one - your application path, where your executable is.
Then, you can import C-functions the pinvoke[^] way.
More info here[^] and here[^]
If you're lucky, you can use this tool[^] to convert all your dll functions into C# function calls.
More tools available here[^].
-- Log Wizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
Thank you very much, John.
I will see and try ...
|
|
|
|
|
To explain what I am trying to do, I want to create a generic abstract base that inherits from another generic class that also needs to implement IDisposable.
Kind of like this.
public abstract class ObjectCollection<T> : Dictionary<int,T> where T : ISomeInterface, IDisposable
{
private DataTable _sourceData;
public abstract LoadData(SqlCommand sourceData);
public void Dispose()
{
_sourceData?.Dispose();
}
}
This isn't working for me as the compiler is interpreting IDisposable as another generic constraint on T. Which gets passed onto the T data type when implemented in a derived class (which doesn't qualify for Disposal). I would like the base class to implement IDisposable. Is that possible or do I need to encase the Dictionary<t> within the base class and provide this[int] indexers?
I tried ISomeInterface : IDisposable but that won't compile.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
You just need to re-order to make IDisposable apply to the class instead of T:
public abstract class ObjectCollection<T> : Dictionary<int,T>, IDisposable where T : ISomeInterface
NB: You should implement the Dispose-pattern properly; this is the auto-generated snippet from VS (2015):
private bool disposedValue = false;
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefèvre wrote: You just need to re-order to make IDisposable apply to the class instead of T
That did it. Thank you. I've been over the MS documentation on generic constraints a dozen times and they never mention that useful piece of information.
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|
|
Maybe you'll find my way of writing it helpful in terms of clarity:
public abstract class ObjectCollection<T> : Dictionary<int,T>, IDisposable
where T : ISomeInterface
{
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Hello Guys,
i would like to ask about how to view the office files (.docx, .xlsx, .pptx) in windows 8.1 app.
modified 2-Mar-16 10:26am.
|
|
|
|
|
You want to preview it within the app itself or just load the doc ?
<tag>I have no tag
|
|
|
|
|
just load it and preview in my app
|
|
|
|
|
When an object A needs to know that something "interesting" happened in object B, object B has an event for that, and A can subscribe to that event. Works well if A and B reside in the same program.
Now imagine A on one computer, and B on a different computer, connected with a not so stable wireless network. Of course, events can be sent via .Net Remoting or WCF. But things become naughty when the connection breaks. .Net Remoting may automatically re-establish the connection, WCF is more of a WTF here.
But anyway, we want B to make sure that the event was sent to all subscribers, and try to send it until it eventually succeeds.
Are there any components available which wrap those extra concerns or do we need to write our own "events" (including the subscription/unsubscription process, sending with a list of pending subscribers, connection fault handling) here? Or would you prefer a different architecture (e.g. A polls the state of B)?
Edit:
Let me create an example for that scenario. We have to take care of a flock of sheep. A shepherding drone is hovering over the area and searching for wolves. After detection of a wolf, it will notify the dogs and tell them where the wolves are etc. In most case there is one drone and one dog, but sometimes there may be many. With some trees around, the connection between the drone and the network may get disrupted.
An alternative solution is the dogs querying the drone's LastWolfDetected property in short intervals. Or the drones sending the LastWolfDetected message to a server, and the dogs query the server.
Anyway, the dogs must be informed reliably.
modified 3-Mar-16 3:18am.
|
|
|
|
|
Would WCF with reliable messaging help you? I kind of think that is what you are looking for.
"You'd have to be a floating database guru clad in a white toga and ghandi level of sereneness to fix this goddamn clusterfuck.", BruceN[ ^]
|
|
|
|
|
|
Bernhard Hiller wrote: But does it really reconnect automatically? No, it doesn't. Reliable Messaging basically just ensures that the sender knows whether a message has been received or not, no more, no less. For automatic reconnection you'll have to implement your own solution.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
OK, so we have something similar (I guess) here that uses SignalR. We keep track of connected clients on the server side. Now, if any client is disconnected, server marks it. The client will then try and reconnect. When that happens, it is unmarked. During this time, if any message was sent, we know how many clients have not received it. So we send it across. Here are the steps we used:
- When the client first connects, it sends a unique value that helps identification (since SignalR connectionIds are not persistent).
- This is saved in dictionary with value as true (for connected).
- When the client is disconnected, the value is set to false.
- When the notification is sent from server to client, we check if there is any client with value as false in the dictionary. If yes, we save the client identifiers.
- Next time they connect, the notification is sent again.
So, in drone-sheep-wolf-dog scene,
- Drone notes all the dogs available.
- If any dogs runs away to eat grass or whatever, it makes note of that too.
- If a wolf is noticed, all dogs are notified. Drone also knows one dog is not there and will need to notify this dog later.
- As soon as dog is back, it is send message.
- If any new dog joins in, that too gets the message.
Now, this assumes that drone is always functional. If drone can fail to retain this information, it can be saved to database. In that case, on any new connection, check drone cache and also database for any pending messages.
"You'd have to be a floating database guru clad in a white toga and ghandi level of sereneness to fix this goddamn clusterfuck.", BruceN[ ^]
|
|
|
|
|