Results 1 to 5 of 5

Thread: [RESOLVED] Calling a C/C++ string search function from a VB thread

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved [RESOLVED] Calling a C/C++ string search function from a VB thread

    I created a STRING SEARCH function in C/C++ - and I'm trying to use it in a multi-threaded situation in VB.

    I started this problem in a thread in the C/C++ section of the forum - here

    http://www.vbforums.com/showthread.php?t=675943

    At any rate - my last post shows me getting this error trying to call the function.

    Ran the code - got to that point - and in the immediate window I did

    Code:
    ?firstIndexOfKeyword("i had fancy italian food for lunch", {"meh", "feh", "italian"}, 3)
    {"An exception 'Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException' occurred"}
        _HResult: -2146232832
        _message: "Error in the application."
        Data: {System.Collections.ListDictionaryInternal}
        HelpLink: Nothing
        HResult: -2146232832
        InnerException: Nothing
        IsTransient: False
        Message: "An exception 'Microsoft.VisualStudio.Debugger.Runtime.CrossThreadMessagingException' occurred"
        Source: "Microsoft.VisualStudio.Debugger.Runtime"
        StackTrace: "   at Microsoft.VisualStudio.Debugger.Runtime.Main.ThrowCrossThreadMessageException(String formatString)     at System.Windows.Forms.SafeNativeMethods.GetWindowTextLength(HandleRef hWnd)     at System.Windows.Forms.Control.get_WindowText()     at System.Windows.Forms.Form.get_WindowText()     at System.Windows.Forms.Control.get_Text()     at System.Windows.Forms.Form.get_Text()     at System.Windows.Forms.Form.ToString()"
        TargetSite: {Void ThrowCrossThreadMessageException(System.String)}
    And got a pop-up error about not finding the ENTRY point and this ugly cross threading error...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Calling a C/C++ string search function from a VB thread

    So, does the code work correctly when used in a single thread? What about in multiple threads? Is it just when you use the Immediate window that the issue arises? The issue appears to be that ToString is being called on a Form from a background thread, but I'm not 100% sure where that would be occurring.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Calling a C/C++ string search function from a VB thread

    Ok - I took this issue out of the immediate window - don't need to add more to my problem then I need

    Took the spot where I was doing the breakpoint - and instead of the immediate window I added this code to call the firstIndexOfKeyword() function
    Code:
        Private Sub ScanFile(ByVal FSObParam As Object)
    
            Dim x As Object = firstIndexOfKeyword("i had fancy italian food for lunch", {"meh", "feh", "italian"}, 3)
    
            Dim FSOb As New FSObject
            FSOb = DirectCast(FSObParam, FSObject)
    and I am getting this error

    Code:
    System.EntryPointNotFoundException was unhandled
      Message=Unable to find an entry point named 'firstIndexOfKeyword' in DLL 'D:\ACS Desktop\dcx\dcx\Debug\StringLibrary.dll'.
      Source=Librarian
      TypeName=""
      StackTrace:
           at Librarian.Librarian.firstIndexOfKeyword(String s, String[] substr, Int32 substrLength)
           at Librarian.Librarian.ScanFile(Object FSObParam) in D:\ACS Desktop\dcx\dcx\Librarian\Librarian.vb:line 145
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.runTryCode(Object userData)
           at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart(Object obj)
      InnerException:
    I am sure I am missing something from the C/C++ project - first time trying to work with C/C++.

    This is in a file called StringLibrary.cpp

    Code:
    // StringLibrary.cpp : Defines the exported functions for the DLL application.
    //
    
    #include "stdafx.h"
    
    __declspec(dllexport) int firstIndexOfKeyword(char *str, char **keywords, int nKeywords) {
    	int i, j, k;
    	int keywordlen;
    	int len = strlen(str);
    
    	for(k = 0; k < nKeywords; k++)
    	{
    		keywordlen = strlen(keywords[k]);
    
    		for(i = 0; i <= len - keywordlen; i++)
    		{
    			for(j = 0; j < keywordlen; j++)
    			{
    				if(keywords[k][j] != str[i + j])
    					j = keywordlen+1;
    			}
    
    			if(j == keywordlen)
    				return i;
    		}
    	}
    
    	return -1;
    }
    Last edited by szlamany; Mar 31st, 2012 at 05:44 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Calling a C/C++ string search function from a VB thread

    That error message certainly makes it sound like the function is not exported correctly in the C++ project but it's far too long since I wrote any C++ to be able to help in that regard I'm afraid. I see that Atheist got it working so I'm not sure what the issue might be.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Calling a C/C++ string search function from a VB thread

    This issue is resolved - refer to the other thread in the first post to see solutuions.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width