|
That's too much code to go through. You should have only shared relevant code and marked the line where the error is.
Looking at the message, you are trying to read a character at some location in the string. The location index is larger than string length. Following demonstrates what you are doing, somewhere in your code:
string hello = "hello";
char someCharacter = hello[10];
"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[ ^]
|
|
|
|
|
Well, there you go - lots of places where you use Substring but don't check to see if you have strings of that length. You know, as each of these tests appears to start at the first character, you could just use StartsWith instead. If you don't do that, you're going to have to check the length of the string in each case.
This space for rent
|
|
|
|
|
Member 12301443 wrote: when i run this code Which code? You didn't show any. If you're referring to the code of some article here on CodeProject then you chose the wrong forum: Post your question on the message board of the article instead (which you'll find at the bottom of its page).
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
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[ ^]
|
|
|
|
|