problem with dll in clr project

  • I have problem with clr project.

    for example:

    i have external MyDLL.dll with function int add (int i, int j)

    in CLR project I have MyCLR.dll with function int clr_add (int i, int j)

    Problem:Can i use in clr_add external dll (MyDLL.dll)?

    in MyCLR.dll I have:

    ...

    ...

    [Microsoft::SqlServer::Server::SqlProcedure]

    static int clr_add(int i, int j)

    {

    typedef int (*CALLBACK LPFNDLLFUNC1)(int,int);

    HINSTANCE hDLL = NULL; // Handle to DLL

    LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer

    hDLL = LoadLibrary(L"MyDLL.dll");

    lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"add");

    int i = lpfnDllFunc1(4,6);

    return i;

    }

    --------------------------------------------------------------------

    in MS SQL :

    CREATE ASSEMBLY assembly_add

    FROM 'c:\_clr\MyCLR.dll'

    WITH PERMISSION_SET = UNSAFE

    go

    CREATE PROCEDURE MyStoredProc @i int, @j-2 int

    AS EXTERNAL NAME assembly_add.[add].clr_add

    declare @w int

    exec @w = MyStoredProc 6,2

    print @w

    Error:

    Msg 6522, Level 16, State 1, Procedure MyStoredProc, Line 0

    A .NET Framework error occurred during execution of user-defined routine or aggregate "MyStoredProc": .

    in my CLR project Common Language Runtime Support = /clr: pure,

    my question: how can i in CLR SQL project use external .dll??

  • Not sure what you are trying to do, but to use the external dll, cant you just add it as 'reference' and then use it?

    ---------------------------------------------------------------------------------

  • A better question... what does the CLR actually do and why do you think you need a CLR to do it?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Actually in SQL CLR programming you are limited in what you can add as a reference, you have to add the assembly to SQL Server FIRST then you can reference it. I don't think the method you are looking at is allowed even in an UNSAFE SQLCLR module. Also, Jeff Moden had a good question, why are you doing this in CLR?

    CEWII

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply