Callback in declare problem

Hi, I try to emulate this code in c from this library.:

[code]int do_clone(git_repository *repo, int argc, char **argv)
progress_data pd = {{0}};
git_repository *cloned_repo = NULL;
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
const char *url = argv[1];
const char *path = argv[2];
int error;

(void)repo; /* unused */

/* Validate args */
if (argc < 3) {
	printf ("USAGE: %s <url> <path>\

", argv[0]);
return -1;

/* Set up options */
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts;
clone_opts.fetch_opts.callbacks.sideband_progress = sideband_progress;
clone_opts.fetch_opts.callbacks.transfer_progress = &fetch_progress;
clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb;
clone_opts.fetch_opts.callbacks.payload = &pd;

/* Do the clone */
error = git_clone(&cloned_repo, url, path, &clone_opts);

if (error != 0) {
const git_error *err = giterr_last();
if (err) printf("ERROR %d: %s
", err->klass, err->message);
else printf("ERROR %d: no detailed info
", error);
else if (cloned_repo) git_repository_free(cloned_repo);
return error;

With next xojo code:

[code]Protected Sub Clone(url As String, localPath As String)
’ Clone a remote repository.

If Not IsAvailable Then Raise GetIOException(“git2 lib are not availble”)

Dim ret As Integer

Dim pd As Ptr

Dim checkoutOptStruct As git_checkout_options
Dim checkoutOptMB As New MemoryBlock(checkoutOptStruct.Size)
Dim checkoutOptPtr As Ptr= checkoutOptMB

ret= git_checkout_init_options(checkoutOptPtr, GIT_CHECKOUT_OPTIONS_VERSION)
checkoutOptStruct= checkoutOptPtr.git_checkout_options
checkoutOptStruct.checkout_strategy= CType(git_checkout_strategy_t.GIT_CHECKOUT_SAFE, UInt32)
checkoutOptStruct.progress_cb= AddressOf handler_checkout_progress
checkoutOptStruct.progress_payload= pd

Dim cloneOptStruct As git_clone_options
Dim cloneOptMB As New MemoryBlock(cloneOptStruct.Size)
Dim cloneOptPtr As Ptr= cloneOptMB

ret= git_clone_init_options(cloneOptPtr, GIT_CLONE_OPTIONS_VERSION)
cloneOptStruct= cloneOptPtr.git_clone_options

cloneOptStruct.checkout_opts= checkoutOptStruct
cloneOptStruct.fetch_opts.callbacks.sideband_progress= AddressOf handler_sideband_progress
cloneOptStruct.fetch_opts.callbacks.transfer_progress= AddressOf handler_fetch_progress

cloneOptStruct.fetch_opts.callbacks.credentials= AddressOf handler_cred_acquire_cb // <- here are the problem

cloneOptStruct.fetch_opts.callbacks.payload= pd

Dim repo As Ptr
ret= git_clone(repo, url, localPath, cloneOptPtr)

If ret> 0 Then // callback
ElseIf ret< 0 Then // err
Dim errPtr As Ptr= giterr_last
Dim errStruct As git_error= errPtr.git_error
Dim errMB As MemoryBlock= errStruct.message

System.DebugLog CurrentMethodName+ " err:"+ Str(errStruct.klass)+ " msg:"+ errMB.CString(0)

End If

If repo<> Nil Then git_repository_free(repo)
End Sub

No call ‘handler_cred_acquire_cb’ function:

[code]Private Function handler_cred_acquire_cb(out As Ptr, url As CString, username_from_url As CString, allowed_types As UInt32, payload As Ptr) As Int32
Dim error As Integer

Return error
End Function

  1. I compile the library and the example and works in visualStudio.
  2. Works on Xojo when NO call the callback function.
  3. The structures seems to be fine, no error.
  4. Returns these error: > [2620] libgit2.Clone err:12 msg:request failed with status code: 401 <

I know I can create executable and debug from VisualStudio the library, but I dont know how.

Thanks for the input.

When I put a breakpoint in a callback function, the debuger stop when the library call the callback funtion?

A quick look at the library looks like the ‘out’ parameter of handler_cred_acquire_cb should be byref.

Private Function handler_cred_acquire_cb(byref out As Ptr, url As CString, username_from_url As CString, allowed_types As UInt32, payload As Ptr) As Int32

[quote=402284:@jim mckay]A quick look at the library looks like the ‘out’ parameter of handler_cred_acquire_cb should be byref.

Yes, I did cahnge that, but that’s not the problem, the problem was the struct, change the struct don’t change the MemoryBlock, I had to copy the struct to MB, weird, but works.

Anyway, thank you for take your time to see and aswer.

PD: debug the .dll in Visual Studio when I call a .dll from xojo executable is pretty easy, just googled.